#include "IQmathLib.h"
#include "DSP281x_Device.h"

#include <adc_tools.h>
#include <alg_simple_scalar.h>
#include <edrk_main.h>
#include <math.h>
#include <mathlib.h>
#include <message2.h>
#include <optical_bus.h>
#include <params.h>
#include <params_norma.h>
#include <sync_tools.h>
#include <v_rotor.h>
#include <vector.h>

#include "control_station.h"
#include "global_time.h"
#include "vector_control.h"
#include "x_basic_types.h"
#include "xp_cds_in.h"
#include "xp_hwp.h"
#include "xp_project.h"
#include "modbus_table_v2.h"
#include "filter_v1.h"
#include "v_rotor_22220.h"
#include "log_params.h"
#include "break_regul.h"
#include "logs_hmi.h"
#include "CAN_Setup.h"
#include "params_temper_p.h"


void func_unpack_answer_from_TMS_RS232(CMD_TO_TMS_STRUCT *pcommand)
{
    // Контрольнаy сумма
    unsigned int DataOut;
    int Data, Data1, Data2, DataAnalog1, DataAnalog2, DataAnalog3, DataAnalog4, i;
    unsigned int h;
    volatile unsigned char *pByte;
    //  static int vs11,vs12,vs1;
    //  static int DataCnt=0;
    //  int GoT,Assemble_scheme;
    //  static int prev_temp_Rele1=0, temp_Rele1=0, prev_temp_Rele2=0, temp_Rele2=0;

    static int flag_prev_turn_on = 0;
    static int flag_prev_turn_off = 0;
    static int prev_byte01_bit4 = 0;
    static int prev_byte01_bit1 = 0;
    static int flag_wait_revers_sbor = 1;
    static int flag_wait_revers_go = 1;

    static unsigned int count_transmited = 0;


    // Разбираем полy команды
    // Все это надо пихнуть себе

    if ((sizeof(CMD_TO_TMS_STRUCT)-5)>CONTROL_STATION_MAX_RAW_DATA)
        xerror(main_er_ID(2),(void *)0);



    // перепакуем из байтов в слова, т.к. в RS232 данные идут байтами
    pByte = (unsigned char *)(pcommand);//->analog_data.analog1_lo;


    pByte++;
    pByte++;

    for (h=0;h<sizeof(TMS_TO_TERMINAL_STRUCT)-5;h++)
    {
       if (h%2)
       {
           control_station.raw_array_data[CONTROL_STATION_TERMINAL_RS232][h>>1].all |= (  (*pByte) << 8) & 0xff00;
       }
       else
           control_station.raw_array_data[CONTROL_STATION_TERMINAL_RS232][h>>1].all = (   (*pByte)     ) & 0x00ff;

       pByte++;
    }

}



void func_pack_answer_to_TMS(TMS_TO_TERMINAL_STRUCT *reply_a)
{
	// Контрольнаy сумма
	unsigned int DataOut;
	int Data1, Data2, DataAnalog1, DataAnalog2, DataAnalog3, DataAnalog4, i;
	float Data;
	unsigned char *pByte;
	//	static int vs11,vs12,vs1;
	//	static int DataCnt=0;
	//	int GoT,Assemble_scheme;
	//	static int prev_temp_Rele1=0, temp_Rele1=0, prev_temp_Rele2=0, temp_Rele2=0;

	static int flag_prev_turn_on = 0;
	static int flag_prev_turn_off = 0;
	static int prev_byte01_bit4 = 0;
	static int prev_byte01_bit1 = 0;
	static int flag_wait_revers_sbor = 1;
	static int flag_wait_revers_go = 1;

	static unsigned int count_transmited = 0;
	/*	const указатель на структуру стандартной команды
	настроили на буфер приема */

//	edrk.data_to_message2[1] = _IQtoF(filter.iqU_1_long)*NORMA_ACP;
//	edrk.data_to_message2[2] = _IQtoF(filter.iqU_2_long)*NORMA_ACP;


	//For instance
	//reply->digit_data.byte01.byte_data = 0x43;


	//1
	Data = _IQtoF(filter.iqU_1_long)*NORMA_ACP;
	reply_a->analog_data.analog1_lo = LOBYTE(Data);
	reply_a->analog_data.analog1_hi = HIBYTE(Data);
	//2
	Data = _IQtoF(filter.iqU_2_long)*NORMA_ACP;//(project.adc[0].read.pbus.adc_value[1] - 2330)/4096*3.0/62.2*1000.0;
	reply_a->analog_data.analog2_lo = LOBYTE(Data);
	reply_a->analog_data.analog2_hi = HIBYTE(Data);

	//3
    Data = _IQtoF(filter.iqUin_m1)*NORMA_ACP;//(project.adc[0].read.pbus.adc_value[2] - 2330)/4096*3.0/62.2*1000.0;
	reply_a->analog_data.analog3_lo = LOBYTE(Data);
	reply_a->analog_data.analog3_hi = HIBYTE(Data);

//4
//	Data = edrk.Status_Sbor;//_IQtoF(filter.iqUin_m2)*NORMA_ACP;//(project.adc[0].read.pbus.adc_value[3] - 2330)/4096*3.0/62.2*1000.0;
    Data = _IQtoF(filter.iqUin_m2)*NORMA_ACP;//(project.adc[0].read.pbus.adc_value[3] - 2330)/4096*3.0/62.2*1000.0;
//	Data = (_IQtoF((filter.Power) * 9000.0)); //Мощность двигателя текущая кВт
	reply_a->analog_data.analog4_lo = LOBYTE(Data);
	reply_a->analog_data.analog4_hi = HIBYTE(Data);

//5
	Data = edrk.power_kw; //Мощность двигателя текущая кВт
//	Data = (_IQtoF((analog.Power) * 9000.0)); //Мощность двигателя текущая кВт
	//_IQtoF(analog.iqIin_1)*NORMA_ACP;//project.adc[0].read.pbus.adc_value[0];
	reply_a->analog_data.analog5_lo = LOBYTE(Data);
	reply_a->analog_data.analog5_hi = HIBYTE(Data);

	Data = _IQtoF(analog.iqIin_sum)*NORMA_ACP;//project.adc[0].read.pbus.adc_value[1];
	reply_a->analog_data.analog6_lo = LOBYTE(Data);
	reply_a->analog_data.analog6_hi = HIBYTE(Data);

	
	Data = _IQtoF(filter.iqIm_1)*NORMA_ACP;//project.adc[0].read.pbus.adc_value[2];
	reply_a->analog_data.analog7_lo = LOBYTE(Data);
	reply_a->analog_data.analog7_hi = HIBYTE(Data);

	Data = _IQtoF(filter.iqIm_2)*NORMA_ACP;//project.adc[0].read.pbus.adc_value[3];
	reply_a->analog_data.analog8_lo = LOBYTE(Data);
	reply_a->analog_data.analog8_hi = HIBYTE(Data);

	Data = (int)(edrk.temper_edrk.max_real_int_temper_u);
	reply_a->analog_data.analog9_lo = LOBYTE(Data);
	reply_a->analog_data.analog9_hi = HIBYTE(Data);

    Data = (int) (edrk.temper_edrk.max_real_int_temper_water);
	reply_a->analog_data.analog10_lo = LOBYTE(Data);
	reply_a->analog_data.analog10_hi = HIBYTE(Data);

	Data = (int) (edrk.p_water_edrk.filter_real_int_p_water[0]);
	reply_a->analog_data.analog11_lo = LOBYTE(Data);
	reply_a->analog_data.analog11_hi = HIBYTE(Data);

	Data = (int) (edrk.temper_edrk.max_real_int_temper_air);//_IQtoF(edrk.f_stator)*F_STATOR_MAX;//
	reply_a->analog_data.analog12_lo = LOBYTE(Data);
	reply_a->analog_data.analog12_hi = HIBYTE(Data);

	Data =    fast_round(_IQtoF(edrk.zadanie.iq_ZadanieU_Charge_rmp)*NORMA_ACP);//edrk.I_zad_vozbud;//
	reply_a->analog_data.analog13_lo = LOBYTE(Data);
	reply_a->analog_data.analog13_hi = HIBYTE(Data);

	Data = edrk.zadanie.oborots_zad;//edrk.I_zad_vozbud_exp;//
	reply_a->analog_data.analog14_lo = LOBYTE(Data);
	reply_a->analog_data.analog14_hi = HIBYTE(Data);

	Data = edrk.zadanie.power_zad;//edrk.I_cur_vozbud;//
	reply_a->analog_data.analog15_lo = LOBYTE(Data);
	reply_a->analog_data.analog15_hi = HIBYTE(Data);

	Data = edrk.zadanie.Izad;//edrk.I_cur_vozbud_exp;//
	reply_a->analog_data.analog16_lo = LOBYTE(Data);
	reply_a->analog_data.analog16_hi = HIBYTE(Data);

	Data = fast_round(_IQtoF(edrk.Kplus)*1000.0);//edrk.W_zad_mA;//
	reply_a->analog_data.analog17_lo = LOBYTE(Data);
	reply_a->analog_data.analog17_hi = HIBYTE(Data);

Data = fast_round(edrk.freq_50hz_1/10.0);//edrk.Zadanie2VozbudING;//
	reply_a->analog_data.analog18_lo = LOBYTE(Data);
	reply_a->analog_data.analog18_hi = HIBYTE(Data);

Data =fast_round(_IQtoF(edrk.f_stator)*NORMA_FROTOR*100.0);// 0;//edrk.Zadanie2VozbudMY;//
	reply_a->analog_data.analog19_lo = LOBYTE(Data);
	reply_a->analog_data.analog19_hi = HIBYTE(Data);

Data = fast_round(_IQtoF(edrk.k_stator1)*10000.0);// edrk.W_from_all;
	reply_a->analog_data.analog20_lo = LOBYTE(Data);
	reply_a->analog_data.analog20_hi = HIBYTE(Data);

Data = _IQtoF(vect_control.iqId1)*NORMA_ACP;//0;//_IQtoF(edrk.test_rms_Iu)*NORMA_ACP; //fast_round(_IQtoF(WRotor.iqWRotorImpulses1)*NORMA_FROTOR*1000.0);// edrk.W_from_DISPLAY;
	reply_a->analog_data.analog21_lo = LOBYTE(Data);
	reply_a->analog_data.analog21_hi = HIBYTE(Data);

Data = _IQtoF(vect_control.iqIq1)*NORMA_ACP;// 0;//_IQtoF(edrk.test_rms_Ua)*NORMA_ACP;// fast_round(_IQtoF(WRotor.iqWRotorImpulses2)*NORMA_FROTOR*1000.0);//600.0*1000000000.0/WRotor.iqWRotorImpulses1;//edrk.W_from_SVU;
	reply_a->analog_data.analog22_lo = LOBYTE(Data);
	reply_a->analog_data.analog22_hi = HIBYTE(Data);

//Data = fast_round(_IQtoF(WRotor.iqWRotorSumFilter3)*NORMA_FROTOR*100.0*60.0);//edrk.oborots;//fast_round(_IQtoF(WRotorPBus.iqAngle1F)*360.0);//600.0*1000000000.0/WRotor.iqWRotorImpulses2;//edrk.W_from_ZADAT4IK;
Data =  _IQtoF(WRotor.iqWRotorSumFilter) * NORMA_FROTOR*600.0;//edrk.oborots;
	reply_a->analog_data.analog23_lo = LOBYTE(Data);
	reply_a->analog_data.analog23_hi = HIBYTE(Data);

Data = fast_round(edrk.f_rotor_hz*100.0);//fast_round(_IQtoF(WRotorPBus.iqAngle2F)*360.0);//;
	reply_a->analog_data.analog24_lo = LOBYTE(Data);
	reply_a->analog_data.analog24_hi = HIBYTE(Data);

//Data = _IQtoF(edrk.k_stator1)*10000;//;
Data =  edrk.period_calc_pwm_int2;//fast_round(_IQtoF(rotor_22220.iqFdirty)*NORMA_FROTOR*1000.0);
	reply_a->analog_data.analog25_lo = LOBYTE(Data);
	reply_a->analog_data.analog25_hi = HIBYTE(Data);

Data = edrk.power_kw_full; //Мощность двигателя текущая кВт
//fast_round(_IQtoF(WRotor.iqWRotorCalcBeforeRegul2)*NORMA_FROTOR*1000.0);
	reply_a->analog_data.analog26_lo = LOBYTE(Data);
	reply_a->analog_data.analog26_hi = HIBYTE(Data);

Data =  edrk.Sbor_Mode;//fast_round(_IQtoF(WRotorPBus.iqWRotorCalcBeforeRegul1)*NORMA_FROTOR*1000.0);//edrk.count_lost_interrupt;
	reply_a->analog_data.analog27_lo = LOBYTE(Data);
	reply_a->analog_data.analog27_hi = HIBYTE(Data);

Data =  edrk.Stage_Sbor;// fast_round(_IQtoF(WRotorPBus.iqWRotorCalcBeforeRegul2)*NORMA_FROTOR*1000.0);;
	reply_a->analog_data.analog28_lo = LOBYTE(Data);
	reply_a->analog_data.analog28_hi = HIBYTE(Data);

Data = fast_round(_IQtoF(edrk.Izad_out)*NORMA_ACP);//edrk.I_zad_vozbud;//;
	reply_a->analog_data.analog29_lo = LOBYTE(Data);
	reply_a->analog_data.analog29_hi = HIBYTE(Data);

Data = edrk.period_calc_pwm_int1;
	reply_a->analog_data.analog30_lo = LOBYTE(Data);
	reply_a->analog_data.analog30_hi = HIBYTE(Data);

    Data = (int)edrk.temper_acdrive.winding.max_real_int_temper;
    reply_a->analog_data.analog31_lo = LOBYTE(Data);
    reply_a->analog_data.analog31_hi = HIBYTE(Data);
    Data = (int)edrk.temper_acdrive.bear.max_real_int_temper;
    reply_a->analog_data.analog32_lo = LOBYTE(Data);
    reply_a->analog_data.analog32_hi = HIBYTE(Data);



	Data = (int)(edrk.temper_edrk.real_int_temper_u[0]);
	reply_a->analog_data.analog33_lo = LOBYTE(Data);
	reply_a->analog_data.analog33_hi = HIBYTE(Data);

    Data = (int)(edrk.temper_edrk.real_int_temper_u[1]);
    reply_a->analog_data.analog34_lo = LOBYTE(Data);
    reply_a->analog_data.analog34_hi = HIBYTE(Data);
    Data = (int)(edrk.temper_edrk.real_int_temper_u[2]);
    reply_a->analog_data.analog35_lo = LOBYTE(Data);
    reply_a->analog_data.analog35_hi = HIBYTE(Data);
    Data = (int)(edrk.temper_edrk.real_int_temper_u[3]);
    reply_a->analog_data.analog36_lo = LOBYTE(Data);
    reply_a->analog_data.analog36_hi = HIBYTE(Data);
    Data = (int)(edrk.temper_edrk.real_int_temper_u[4]);
    reply_a->analog_data.analog37_lo = LOBYTE(Data);
    reply_a->analog_data.analog37_hi = HIBYTE(Data);
    Data = (int)(edrk.temper_edrk.real_int_temper_u[5]);
    reply_a->analog_data.analog38_lo = LOBYTE(Data);
    reply_a->analog_data.analog38_hi = HIBYTE(Data);
    Data = (int)(edrk.temper_edrk.real_int_temper_u[6]);
    reply_a->analog_data.analog39_lo = LOBYTE(Data);
    reply_a->analog_data.analog39_hi = HIBYTE(Data);
    Data = (int)(edrk.temper_edrk.real_int_temper_air[0]);
    reply_a->analog_data.analog40_lo = LOBYTE(Data);
    reply_a->analog_data.analog40_hi = HIBYTE(Data);
    Data = (int)(edrk.temper_edrk.real_int_temper_air[1]);
    reply_a->analog_data.analog41_lo = LOBYTE(Data);
    reply_a->analog_data.analog41_hi = HIBYTE(Data);
    Data = (int)(edrk.temper_edrk.real_int_temper_air[2]);
    reply_a->analog_data.analog42_lo = LOBYTE(Data);
    reply_a->analog_data.analog42_hi = HIBYTE(Data);

    Data = (int)(edrk.temper_edrk.real_int_temper_air[3]);
    reply_a->analog_data.analog43_lo = LOBYTE(Data);
    reply_a->analog_data.analog43_hi = HIBYTE(Data);
    Data = (int)(edrk.temper_edrk.real_int_temper_water[0]); // external
    reply_a->analog_data.analog44_lo = LOBYTE(Data);
    reply_a->analog_data.analog44_hi = HIBYTE(Data);
    Data = (int)(edrk.temper_edrk.real_int_temper_water[1]); // internal
    reply_a->analog_data.analog45_lo = LOBYTE(Data);
    reply_a->analog_data.analog45_hi = HIBYTE(Data);


    Data =  fast_round(_IQtoF(simple_scalar1.pidF.OutMax)*NORMA_ACP);//edrk.auto_master_slave.prev_status;//fast_round(_IQtoF(edrk.zadanie.iq_ZadanieU_Charge_rmp)*NORMA_ACP);
    reply_a->analog_data.analog46_lo = LOBYTE(Data);
    reply_a->analog_data.analog46_hi = HIBYTE(Data);


    Data =  fast_round(_IQtoF(edrk.zadanie.iq_Izad_rmp)*NORMA_ACP);
    reply_a->analog_data.analog47_lo = LOBYTE(Data);
    reply_a->analog_data.analog47_hi = HIBYTE(Data);
    Data =  fast_round(_IQtoF(edrk.zadanie.iq_fzad_rmp)*NORMA_FROTOR*100.0);
    reply_a->analog_data.analog48_lo = LOBYTE(Data);
    reply_a->analog_data.analog48_hi = HIBYTE(Data);
    Data = fast_round(_IQtoF(edrk.zadanie.iq_kzad_rmp)*10000.0);
    reply_a->analog_data.analog49_lo = LOBYTE(Data);
    reply_a->analog_data.analog49_hi = HIBYTE(Data);
    Data = fast_round(_IQtoF(edrk.zadanie.iq_oborots_zad_hz_rmp)*NORMA_FROTOR*60.0);
    reply_a->analog_data.analog50_lo = LOBYTE(Data);
    reply_a->analog_data.analog50_hi = HIBYTE(Data);

    Data = fast_round(_IQtoF(edrk.zadanie.iq_power_zad_rmp)*NORMA_ACP*NORMA_ACP/1000.0);
    reply_a->analog_data.analog51_lo = LOBYTE(Data);
    reply_a->analog_data.analog51_hi = HIBYTE(Data);

    Data = _IQtoF(vect_control.iqId2)*NORMA_ACP;//0;//fast_round( _IQtoF(edrk.zadanie.iq_k_u_disbalance_rmp)*100.0);
    reply_a->analog_data.analog52_lo = LOBYTE(Data);
    reply_a->analog_data.analog52_hi = HIBYTE(Data);

    Data = fast_round(_IQtoF(edrk.zadanie.iq_limit_power_zad_rmp)*NORMA_ACP*NORMA_ACP/1000.0);
    reply_a->analog_data.analog53_lo = LOBYTE(Data);
    reply_a->analog_data.analog53_hi = HIBYTE(Data);

    if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER) {
       Data = fast_round(_IQtoF(turns.pidFvect.Out)*NORMA_ACP);
       reply_a->analog_data.analog54_lo = LOBYTE(Data);
       reply_a->analog_data.analog54_hi = HIBYTE(Data);
       Data = fast_round(_IQtoF(turns.pidFvect.OutMax)*NORMA_ACP);
       reply_a->analog_data.analog55_lo = LOBYTE(Data);
       reply_a->analog_data.analog55_hi = HIBYTE(Data);
       Data =fast_round(_IQtoF(power.pidP.Out)*NORMA_ACP);
       reply_a->analog_data.analog56_lo = LOBYTE(Data);
       reply_a->analog_data.analog56_hi = HIBYTE(Data);
       Data = fast_round(_IQtoF(power.pidP.OutMax)*NORMA_ACP);
    } else {
        Data = fast_round(_IQtoF(simple_scalar1.pidF.Out)*NORMA_ACP);
        reply_a->analog_data.analog54_lo = LOBYTE(Data);
        reply_a->analog_data.analog54_hi = HIBYTE(Data);
        Data = fast_round(_IQtoF(simple_scalar1.pidF.OutMin)*NORMA_ACP);
        reply_a->analog_data.analog55_lo = LOBYTE(Data);
        reply_a->analog_data.analog55_hi = HIBYTE(Data);
        Data =fast_round(_IQtoF(simple_scalar1.pidPower.Out)*NORMA_ACP);
        reply_a->analog_data.analog56_lo = LOBYTE(Data);
        reply_a->analog_data.analog56_hi = HIBYTE(Data);
        Data = fast_round(_IQtoF(simple_scalar1.pidPower.OutMax)*NORMA_ACP);
    }

    reply_a->analog_data.analog57_lo = LOBYTE(Data);
    reply_a->analog_data.analog57_hi = HIBYTE(Data);



    Data = fast_round(_IQtoF(simple_scalar1.Izad)*NORMA_ACP);
    reply_a->analog_data.analog58_lo = LOBYTE(Data);
    reply_a->analog_data.analog58_hi = HIBYTE(Data);

    Data =  fast_round(_IQtoF(edrk.master_Iq)*NORMA_ACP);
    reply_a->analog_data.analog59_lo = LOBYTE(Data);
    reply_a->analog_data.analog59_hi = HIBYTE(Data);

    Data = fast_round(_IQtoF(simple_scalar1.mzz_zad_in2)*NORMA_ACP);//count_transmited++;
    reply_a->analog_data.analog60_lo = LOBYTE(Data);
    reply_a->analog_data.analog60_hi = HIBYTE(Data);
//
    Data = modbus_table_can_in[123].all;//Управление (По мощности, По оборотам)
    reply_a->analog_data.analog61_lo = LOBYTE(Data);
    reply_a->analog_data.analog61_hi = HIBYTE(Data);

    Data = modbus_table_can_in[124].all;//Обороты (заданные)
    reply_a->analog_data.analog62_lo = LOBYTE(Data);
    reply_a->analog_data.analog62_hi = HIBYTE(Data);

    Data = modbus_table_can_in[125].all;//Мощность (заданная)
    reply_a->analog_data.analog63_lo = LOBYTE(Data);
    reply_a->analog_data.analog63_hi = HIBYTE(Data);

    Data = modbus_table_can_in[134].all;//запас мощности
    reply_a->analog_data.analog64_lo = LOBYTE(Data);
    reply_a->analog_data.analog64_hi = HIBYTE(Data);

    Data = fast_round(_IQtoF(simple_scalar1.pidPower.SatErr)*NORMA_ACP);//project.cds_tk[3].optical_data_in.local_count_error;
    reply_a->analog_data.analog65_lo = LOBYTE(Data);
    reply_a->analog_data.analog65_hi = HIBYTE(Data);

    Data = fast_round(_IQtoF(simple_scalar1.pidPower.Fdb)*NORMA_ACP*NORMA_ACP/1000.0);//project.cds_tk[3].optical_data_out.local_count_error;
    reply_a->analog_data.analog66_lo = LOBYTE(Data);
    reply_a->analog_data.analog66_hi = HIBYTE(Data);

    Data = fast_round(_IQtoF(simple_scalar1.pidPower.Ref)*NORMA_ACP*NORMA_ACP/1000.0);//////optical_read_data.count_error_wdog;
    reply_a->analog_data.analog67_lo = LOBYTE(Data);
    reply_a->analog_data.analog67_hi = HIBYTE(Data);


    Data = fast_round(_IQtoF(simple_scalar1.pidPower.Up)*NORMA_ACP);//edrk.auto_master_slave.status;//fast_round(_IQtoF(edrk.zadanie.iq_kplus_u_disbalance_rmp)*1000.0);
    reply_a->analog_data.analog68_lo = LOBYTE(Data);
    reply_a->analog_data.analog68_hi = HIBYTE(Data);

    Data =  fast_round(_IQtoF(pll1.vars.pll_Uq)*NORMA_ACP);
    reply_a->analog_data.analog69_lo = LOBYTE(Data);
    reply_a->analog_data.analog69_hi = HIBYTE(Data);

    Data = fast_round(_IQtoF(pll1.vars.pll_Ud)*NORMA_ACP);
    reply_a->analog_data.analog70_lo = LOBYTE(Data);
    reply_a->analog_data.analog70_hi = HIBYTE(Data);

Data =  fast_round(_IQtoF(simple_scalar1.bpsi_curent)*NORMA_FROTOR*1000.0);
    reply_a->analog_data.analog71_lo = LOBYTE(Data);
    reply_a->analog_data.analog71_hi = HIBYTE(Data);

Data = fast_round(_IQtoF(WRotor.iqWRotorSumFilter2)*NORMA_FROTOR*1000.0); //iqFlong
    reply_a->analog_data.analog72_lo = LOBYTE(Data);
    reply_a->analog_data.analog72_hi = HIBYTE(Data);

//Data =  fast_round(_IQtoF(WRotor.iqWRotorCalc1)*NORMA_FROTOR*1000.0);
Data = fast_round(_IQtoF(edrk.from_uom.iq_level_value_kwt)*NORMA_ACP*NORMA_ACP/1000.0);// ;//edrk.from_uom.level_value;//fast_round(_IQtoF(rotor_22220.iqFdirty)*NORMA_FROTOR*1000.0);
    reply_a->analog_data.analog73_lo = LOBYTE(Data);
    reply_a->analog_data.analog73_hi = HIBYTE(Data);

//Data = fast_round(_IQtoF(WRotor.iqWRotorCalc2)*NORMA_FROTOR*1000.0);
Data =  _IQtoF(vect_control.iqIq2)*NORMA_ACP;//0;//fast_round(_IQtoF(rotor_22220.iqF)*NORMA_FROTOR*1000.0);
    reply_a->analog_data.analog74_lo = LOBYTE(Data);
    reply_a->analog_data.analog74_hi = HIBYTE(Data);

//Data = fast_round(_IQtoF(WRotor.iqWRotorImpulsesBeforeRegul1)*NORMA_FROTOR*1000.0);// edrk.W_from_DISPLAY;
Data =  fast_round(_IQtoF(WRotor.iqWRotorSumFilter)*NORMA_FROTOR*1000.0);
    reply_a->analog_data.analog75_lo = LOBYTE(Data);
    reply_a->analog_data.analog75_hi = HIBYTE(Data);

//Data = fast_round(_IQtoF(WRotor.iqWRotorImpulsesBeforeRegul2)*NORMA_FROTOR*1000.0);//600.0*1000000000.0/WRotor.iqWRotorImpulses1;//edrk.W_from_SVU;
Data =  fast_round(_IQtoF(simple_scalar1.mzz_zad_int)*NORMA_ACP);//;//0;//fast_round(_IQtoF(rotor_22220.iqFlong)*NORMA_FROTOR*1000.0);
    reply_a->analog_data.analog76_lo = LOBYTE(Data);
    reply_a->analog_data.analog76_hi = HIBYTE(Data);

//Data = fast_round(_IQtoF(WRotor.iqWRotorImpulses1)*NORMA_FROTOR*1000.0);// edrk.W_from_DISPLAY;
    Data = _IQtoF(simple_scalar1.Izad)*NORMA_ACP_RMS;// 0;//fast_round(_IQtoF(WRotor.iqWRotorSumRamp)*NORMA_FROTOR*1000.0);
    reply_a->analog_data.analog77_lo = LOBYTE(Data);
    reply_a->analog_data.analog77_hi = HIBYTE(Data);

//Data = fast_round(_IQtoF(WRotor.iqWRotorImpulses2)*NORMA_FROTOR*1000.0);//600.0*1000000000.0/WRotor.iqWRotorImpulses1;//edrk.W_from_SVU;
    Data = WRotor.RotorDirectionSlow;
    reply_a->analog_data.analog78_lo = LOBYTE(Data);
    reply_a->analog_data.analog78_hi = HIBYTE(Data);

Data = fast_round(_IQtoF(simple_scalar1.iqKoefOgran)*1000.0);//0;//fast_round(_IQtoF(WRotor.iqWRotorSum)*NORMA_FROTOR*1000.0);// edrk.W_from_DISPLAY;
    reply_a->analog_data.analog79_lo = LOBYTE(Data);
    reply_a->analog_data.analog79_hi = HIBYTE(Data);

Data = fast_round(_IQtoF(simple_scalar1.iqKoefOgranIzad)*1000.0);//0;//fast_round(_IQtoF(WRotor.iqWRotorSumFilter)*NORMA_FROTOR*1000.0);//600.0*1000000000.0/WRotor.iqWRotorImpulses1;//edrk.W_from_SVU;
    reply_a->analog_data.analog80_lo = LOBYTE(Data);
    reply_a->analog_data.analog80_hi = HIBYTE(Data);

    Data = log_params.cur_volume_of_slow_log;//edrk.power_kw_full; //Мощность двигателя текущая кВт
//  Data = (_IQtoF((analog.Power) * 9000.0)); //Мощность двигателя текущая кВт
    //_IQtoF(analog.iqIin_1)*NORMA_ACP;//project.adc[0].read.pbus.adc_value[0];
    reply_a->analog_data.analog81_lo = LOBYTE(Data);
    reply_a->analog_data.analog81_hi = HIBYTE(Data);

    Data = fast_round(_IQtoF(edrk.zadanie.iq_limit_power_zad)*NORMA_ACP*NORMA_ACP/1000.0);
    reply_a->analog_data.analog82_lo = LOBYTE(Data);
    reply_a->analog_data.analog82_hi = HIBYTE(Data);

    Data = break_result_1;//fast_round(_IQtoF(WRotor.iqWRotorSumFilter3)*NORMA_FROTOR*1000.0);
    reply_a->analog_data.analog83_lo = LOBYTE(Data);
    reply_a->analog_data.analog83_hi = HIBYTE(Data);

    Data = break_result_2;//WRotorPBus.RotorDirectionInstant;
    reply_a->analog_data.analog84_lo = LOBYTE(Data);
    reply_a->analog_data.analog84_hi = HIBYTE(Data);

    Data = fast_round(_IQtoF(edrk.all_limit_koeffs.sum_limit)*1000.0);//WRotorPBus.RotorDirectionCount;
    reply_a->analog_data.analog85_lo = LOBYTE(Data);
    reply_a->analog_data.analog85_hi = HIBYTE(Data);


    Data = fast_round(_IQtoF(edrk.all_limit_koeffs.uom_limit)*1000.0);//WRotorPBus.RotorDirectionSlow2;
    reply_a->analog_data.analog86_lo = LOBYTE(Data);
    reply_a->analog_data.analog86_hi = HIBYTE(Data);

    Data = fast_round(_IQtoF(edrk.all_limit_koeffs.uin_freq_limit)*1000.0);//fast_round(_IQtoF(WRotor.iqWRotorSumRamp)*NORMA_FROTOR*1000.0);
    reply_a->analog_data.analog87_lo = LOBYTE(Data);
    reply_a->analog_data.analog87_hi = HIBYTE(Data);

    Data = _IQtoF(simple_scalar1.Im_regul)*NORMA_ACP_RMS;//(edrk.cantec_reg & 0xff);//edrk.pult_data.TimeToChangePump_from_pult;//0;//fast_round(_IQtoF(WRotor.iqWRotorCalc1Ramp)*NORMA_FROTOR*1000.0);;//WRotor.iqWRotorCalc1Ramp
    reply_a->analog_data.analog88_lo = LOBYTE(Data);
    reply_a->analog_data.analog88_hi = HIBYTE(Data);

    Data = fast_round(_IQtoF(simple_scalar1.pidPower.Ui)*NORMA_ACP);//(edrk.canrec_reg & 0xff);;//edrk.pult_data.nPCH_from_pult;//0;//fast_round(_IQtoF(WRotor.iqWRotorCalc2Ramp)*NORMA_FROTOR*1000.0);;
    reply_a->analog_data.analog89_lo = LOBYTE(Data);
    reply_a->analog_data.analog89_hi = HIBYTE(Data);

    Data = fast_round(_IQtoF(simple_scalar1.pidF.Fdb)*NORMA_FROTOR*1000.0);//(((unsigned long)edrk.canes_reg>>16) & 0x01ff);
    reply_a->analog_data.analog90_lo = LOBYTE(Data);
    reply_a->analog_data.analog90_hi = HIBYTE(Data);

    Data = fast_round(_IQtoF(simple_scalar1.pidF.Ref)*NORMA_FROTOR*1000.0);//(((unsigned long)edrk.canes_reg) & 0x3f);
    reply_a->analog_data.analog91_lo = LOBYTE(Data);
    reply_a->analog_data.analog91_hi = HIBYTE(Data);


    Data = fast_round(_IQtoF(simple_scalar1.pidF.SatErr)*NORMA_ACP);//CanBusOffError;//0;
    reply_a->analog_data.analog92_lo = LOBYTE(Data);
    reply_a->analog_data.analog92_hi = HIBYTE(Data);

    Data = fast_round(_IQtoF(simple_scalar1.pidF.Ui)*NORMA_ACP);//CanTimeOutErrorTR;//0;
    reply_a->analog_data.analog93_lo = LOBYTE(Data);
    reply_a->analog_data.analog93_hi = HIBYTE(Data);

    Data = fast_round(_IQtoF(simple_scalar1.pidF.Up)*NORMA_ACP);//0;
    reply_a->analog_data.analog94_lo = LOBYTE(Data);
    reply_a->analog_data.analog94_hi = HIBYTE(Data);

    Data = fast_round(_IQtoF(simple_scalar1.iq_decr_mzz_power)*1000.0);//0;//simple_scalar1.k_ogr_n
    reply_a->analog_data.analog95_lo = LOBYTE(Data);
    reply_a->analog_data.analog95_hi = HIBYTE(Data);

    Data = fast_round(_IQtoF(simple_scalar1.iq_decr_mzz_power_filter)*1000.0);//fast_round(_IQtoF(edrk.zadanie.rmp_oborots_zad_hz.PosRampPlus1)*NORMA_FROTOR*60.0*450.0*1000.0);
    reply_a->analog_data.analog96_lo = LOBYTE(Data);
    reply_a->analog_data.analog96_hi = HIBYTE(Data);

//    Data = 0;
//    reply_a->analog_data.analog97_lo = LOBYTE(Data);
//    reply_a->analog_data.analog97_hi = HIBYTE(Data);



    pByte = &reply_a->digit_data.byte01.byte_data;
	for (i = 0; i < 59; i++) //zero all dig data
	{
		*(pByte + i) = 0;
	}


//	reply->digit_data.byte01.byte_data = project.cds_in[1].read.pbus.data_in.all & 0xff;
//	reply->digit_data.byte02.byte_data = (project.cds_in[1].read.pbus.data_in.all >> 8) & 0xff;
	
    reply_a->digit_data.byte01.byte_data = edrk.errors.e0.all  & 0xff;
    reply_a->digit_data.byte02.byte_data = (edrk.errors.e0.all >> 8)  & 0xff;

    reply_a->digit_data.byte03.byte_data = edrk.errors.e1.all  & 0xff;
    reply_a->digit_data.byte04.byte_data = (edrk.errors.e1.all >> 8)  & 0xff;

    reply_a->digit_data.byte05.byte_data = edrk.errors.e2.all  & 0xff;
    reply_a->digit_data.byte06.byte_data = (edrk.errors.e2.all >> 8)  & 0xff;

    reply_a->digit_data.byte07.byte_data = edrk.errors.e3.all  & 0xff;
    reply_a->digit_data.byte08.byte_data = (edrk.errors.e3.all >> 8)  & 0xff;

    reply_a->digit_data.byte09.byte_data = edrk.errors.e4.all  & 0xff;
    reply_a->digit_data.byte10.byte_data = (edrk.errors.e4.all >> 8)  & 0xff;

    reply_a->digit_data.byte11.byte_data = edrk.errors.e5.all  & 0xff;
    reply_a->digit_data.byte12.byte_data = (edrk.errors.e5.all >> 8)  & 0xff;

//13
    if (edrk.Status_Perehod_Rascepitel)
        reply_a->digit_data.byte13.bit_data.bit1 = 1;
    else
        reply_a->digit_data.byte13.bit_data.bit1 = 0;

    if (edrk.Status_Rascepitel_Ok)
        reply_a->digit_data.byte13.bit_data.bit0 = 1;
    else
        reply_a->digit_data.byte13.bit_data.bit0 = 0;

    reply_a->digit_data.byte13.bit_data.bit2 = edrk.from_second_pch.bits.MASTER;
    reply_a->digit_data.byte13.bit_data.bit3 = edrk.from_second_pch.bits.RASCEPITEL;

    reply_a->digit_data.byte13.bit_data.bit4 = edrk.warning;
    reply_a->digit_data.byte13.bit_data.bit5 = edrk.overheat;
    reply_a->digit_data.byte13.bit_data.bit6 = edrk.summ_errors;
    reply_a->digit_data.byte13.bit_data.bit7 = edrk.Status_Ready.bits.ready_final;


//    reply_a->digit_data.byte13.byte_data = edrk.errors.e6.all  & 0xff;
//    reply->digit_data.byte14.byte_data = (edrk.errors.e6.all >> 8)  & 0xff;
/*
    reply->digit_data.byte15.byte_data = edrk.errors.e7.all  & 0xff;
    reply->digit_data.byte16.byte_data = (edrk.errors.e7.all >> 8)  & 0xff;

    reply->digit_data.byte17.byte_data = edrk.errors.e8.all  & 0xff;
    reply->digit_data.byte18.byte_data = (edrk.errors.e8.all >> 8)  & 0xff;
*/
//IN2
	reply_a->digit_data.byte14.byte_data = edrk.from_ing1.all & 0xff;//  project.cds_in[1].read.pbus.data_in.all & 0xFF;
	reply_a->digit_data.byte15.byte_data = (edrk.from_ing1.all >> 8) & 0xFF;//(project.cds_in[1].read.pbus.data_in.all >> 8) & 0xFF;

// status plates
	reply_a->digit_data.byte16.bit_data.bit0 = !(project.hwp[0].status == component_Ready);//XProject_balzam.IsReady_reg.bit.XPlaneHWP_Chanals_IsReady;
	reply_a->digit_data.byte16.bit_data.bit1 = !(project.adc[0].status == component_Ready);//XProject_balzam.IsReady_reg.bit.XPlaneHWP_Chanals_IsReady;
    reply_a->digit_data.byte16.bit_data.bit2 = !(project.adc[1].status == component_Ready);
	reply_a->digit_data.byte16.bit_data.bit3 = !(project.cds_in[0].status == component_Ready);//XProject_balzam.IsReady_reg.bit.XPlaneIN0_IsReady;
	reply_a->digit_data.byte16.bit_data.bit4 = !(project.cds_in[1].status == component_Ready);//XProject_balzam.IsReady_reg.bit.XPlaneIN1_IsReady;
//	reply_ans->digit_data.byte21.bit_data.bit5 = !project.cds_in[2].status;//XProject_balzam.IsReady_reg.bit.XPlaneIN2_IsReady;
	reply_a->digit_data.byte16.bit_data.bit5 = !(project.cds_out[0].status == component_Ready);//XProject_balzam.IsReady_reg.bit.XPlaneOUT0_IsReady;
//	reply_ans->digit_data.byte21.bit_data.bit7 = !project.cds_out[1].status;//XProject_balzam.IsReady_reg.bit.XPlaneOUT1_IsReady;
//	reply_ans->digit_data.byte22.bit_data.bit0 = !project.cds_out[2].status;//XProject_balzam.IsReady_reg.bit.XPlaneOUT2_IsReady;
	reply_a->digit_data.byte16.bit_data.bit6 = !(project.cds_tk[0].status == component_Ready);//XProject_balzam.IsReady_reg.bit.XPlaneTK0_IsReady;
	reply_a->digit_data.byte16.bit_data.bit7 = !(project.cds_tk[1].status == component_Ready);//XProject_balzam.IsReady_reg.bit.XPlaneTK1_IsReady;
	reply_a->digit_data.byte17.bit_data.bit0 = !(project.cds_tk[2].status == component_Ready);//XProject_balzam.IsReady_reg.bit.XPlaneTK2_IsReady;
	reply_a->digit_data.byte17.bit_data.bit1 = !(project.cds_tk[3].status == component_Ready);//!XProject_balzam.IsReady_reg.bit.XPlaneTK3_IsReady;
//	reply_ans->digit_data.byte22.bit_data.bit5 = !project.adc[1].status;//XProject_balzam.IsReady_reg.bit.XPlaneHWP_Chanals_IsReady;


//IN1
	reply_a->digit_data.byte17.bit_data.bit2 = project.cds_in[0].read.pbus.data_in.bit.in0;
	reply_a->digit_data.byte17.bit_data.bit3 = project.cds_in[0].read.pbus.data_in.bit.in1;
	reply_a->digit_data.byte17.bit_data.bit4 = project.cds_in[0].read.pbus.data_in.bit.in2;
	reply_a->digit_data.byte17.bit_data.bit5 = project.cds_in[0].read.pbus.data_in.bit.in3;
	reply_a->digit_data.byte17.bit_data.bit6 = project.cds_in[0].read.pbus.data_in.bit.in4;

	reply_a->digit_data.byte17.bit_data.bit7 = project.cds_in[0].read.pbus.data_in.bit.in8;

	reply_a->digit_data.byte18.bit_data.bit0 = project.cds_in[0].read.pbus.data_in.bit.in9;
	reply_a->digit_data.byte18.bit_data.bit1 = project.cds_in[0].read.pbus.data_in.bit.in10;
	reply_a->digit_data.byte18.bit_data.bit2 = project.cds_in[0].read.pbus.data_in.bit.in11;


//out
	reply_a->digit_data.byte18.bit_data.bit3 = edrk.to_ing.bits.ZARYAD_ON;//  project.cds_out[0].write.sbus.data_out.bit.dout0;

	reply_a->digit_data.byte18.bit_data.bit4 = edrk.to_ing.bits.NAGREV_OFF;//project.cds_out[0].write.sbus.data_out.bit.dout1;
	reply_a->digit_data.byte18.bit_data.bit5 = edrk.to_ing.bits.NASOS_1_ON;//project.cds_out[0].write.sbus.data_out.bit.dout2;
	reply_a->digit_data.byte18.bit_data.bit6 = edrk.to_ing.bits.NASOS_2_ON;//project.cds_out[0].write.sbus.data_out.bit.dout3;
	reply_a->digit_data.byte18.bit_data.bit7 = edrk.to_ing.bits.BLOCK_KEY_OFF;//project.cds _out[0].write.sbus.data_out.bit.dout4;
	reply_a->digit_data.byte19.bit_data.bit0 = (edrk.to_shema.bits.UMP_ON_OFF || edrk.to_shema.bits.CROSS_UMP_ON_OFF);//project.cds_out[0].write.sbus.data_out.bit.dout5;
	reply_a->digit_data.byte19.bit_data.bit1 = edrk.to_shema.bits.QTV_ON || edrk.to_shema.bits.QTV_ON_OFF || edrk.to_shema.bits.CROSS_QTV_ON_OFF;//project.cds_out[0].write.sbus.data_out.bit.dout6;
	reply_a->digit_data.byte19.bit_data.bit2 = edrk.to_shema.bits.QTV_OFF;//project.cds_out[0].write.sbus.data_out.bit.dout7;

	reply_a->digit_data.byte19.bit_data.bit3 = edrk.to_ing.bits.RASCEPITEL_OFF;
	reply_a->digit_data.byte19.bit_data.bit4 = edrk.to_ing.bits.RASCEPITEL_ON;
	reply_a->digit_data.byte19.bit_data.bit5 = sync_data.local_flag_sync_1_2;//
	reply_a->digit_data.byte19.bit_data.bit6 = edrk.flag_second_PCH;//
	reply_a->digit_data.byte19.bit_data.bit7 = edrk.to_ing.bits.SMALL_LAMPA_AVARIA;	//project.cds_out[0].write.sbus.data_out.bit.dout15;

//20
	reply_a->digit_data.byte20.bit_data.bit0 = edrk.SumSbor;

	reply_a->digit_data.byte20.bit_data.bit1 = edrk.Status_Ready.bits.ready1;
	reply_a->digit_data.byte20.bit_data.bit2 = edrk.Status_Ready.bits.ready2;
	reply_a->digit_data.byte20.bit_data.bit3 = edrk.Status_Ready.bits.ready3;
	reply_a->digit_data.byte20.bit_data.bit4 = edrk.Status_Ready.bits.ready4;
	reply_a->digit_data.byte20.bit_data.bit5 = edrk.Status_Ready.bits.ready5;
	reply_a->digit_data.byte20.bit_data.bit6 = edrk.Status_Charge;
	reply_a->digit_data.byte20.bit_data.bit7 = edrk.Zaryad_OK;

    reply_a->digit_data.byte21.byte_data = edrk.errors.e6.all  & 0xff;
	reply_a->digit_data.byte22.byte_data = (edrk.errors.e6.all >> 8)  & 0xff;

//	reply_a->digit_data.byte21.bit_data.bit0 = edrk.errors.e6.bits.UO6_KEYS;
//	reply_a->digit_data.byte21.bit_data.bit1 = edrk.errors.e6.bits.UO7_KEYS;
//	reply_a->digit_data.byte21.bit_data.bit2 = edrk.errors.e6.bits.UO1_KEYS;
//    reply_a->digit_data.byte21.bit_data.bit3 = edrk.errors.e6.bits.ERR_PBUS;
//    reply_a->digit_data.byte21.bit_data.bit4 = edrk.errors.e6.bits.ERR_SBUS;
//    reply_a->digit_data.byte21.bit_data.bit5 = edrk.errors.e6.bits.ER_DISBAL_BATT;
//    reply_a->digit_data.byte21.bit_data.bit6 = edrk.errors.e6.bits.ER_RAZBALANS_ALG;
//    reply_a->digit_data.byte21.bit_data.bit7 = edrk.errors.e6.bits.RASCEPITEL_ERROR_NOT_ANSWER;


    reply_a->digit_data.byte23.byte_data = edrk.errors.e7.all  & 0xff;
    reply_a->digit_data.byte24.byte_data = (edrk.errors.e7.all >> 8)  & 0xff;



	// hwp
    reply_a->digit_data.byte25.byte_data = project.hwp[0].read.comp_s.plus.all & 0xff;
    reply_a->digit_data.byte26.byte_data = (project.hwp[0].read.comp_s.plus.all >> 8)  & 0xff;

    reply_a->digit_data.byte27.byte_data = project.hwp[0].read.comp_s.minus.all  & 0xff;
    reply_a->digit_data.byte28.byte_data = (project.hwp[0].read.comp_s.minus.all >> 8)  & 0xff;


    reply_a->digit_data.byte29.bit_data.bit0 = control_station.active_control_station[CONTROL_STATION_TERMINAL_RS232];
    reply_a->digit_data.byte29.bit_data.bit1 = control_station.active_control_station[CONTROL_STATION_TERMINAL_CAN];
    reply_a->digit_data.byte29.bit_data.bit2 = control_station.active_control_station[CONTROL_STATION_INGETEAM_PULT_RS485];
    reply_a->digit_data.byte29.bit_data.bit3 = control_station.active_control_station[CONTROL_STATION_MPU_SVU_CAN];
    reply_a->digit_data.byte29.bit_data.bit4 = control_station.active_control_station[CONTROL_STATION_MPU_KEY_CAN];
    reply_a->digit_data.byte29.bit_data.bit5 = control_station.active_control_station[CONTROL_STATION_MPU_SVU_RS485];
    reply_a->digit_data.byte29.bit_data.bit6 = control_station.active_control_station[CONTROL_STATION_MPU_KEY_RS485];
    reply_a->digit_data.byte29.bit_data.bit7 = control_station.active_control_station[CONTROL_STATION_ZADATCHIK_CAN];

    reply_a->digit_data.byte30.bit_data.bit0 = control_station.alive_control_station[CONTROL_STATION_TERMINAL_RS232];
    reply_a->digit_data.byte30.bit_data.bit1 = control_station.alive_control_station[CONTROL_STATION_TERMINAL_CAN];
    reply_a->digit_data.byte30.bit_data.bit2 = control_station.alive_control_station[CONTROL_STATION_INGETEAM_PULT_RS485];
    reply_a->digit_data.byte30.bit_data.bit3 = control_station.alive_control_station[CONTROL_STATION_MPU_SVU_CAN];
    reply_a->digit_data.byte30.bit_data.bit4 = control_station.alive_control_station[CONTROL_STATION_MPU_KEY_CAN];
    reply_a->digit_data.byte30.bit_data.bit5 = control_station.alive_control_station[CONTROL_STATION_MPU_SVU_RS485];
    reply_a->digit_data.byte30.bit_data.bit6 = control_station.alive_control_station[CONTROL_STATION_MPU_KEY_RS485];
    reply_a->digit_data.byte30.bit_data.bit7 = control_station.alive_control_station[CONTROL_STATION_ZADATCHIK_CAN];


    reply_a->digit_data.byte31.byte_data = optical_read_data.data.cmd.all  & 0xff;
    reply_a->digit_data.byte32.byte_data = (optical_read_data.data.cmd.all >> 8) & 0xff;

    reply_a->digit_data.byte33.byte_data = optical_write_data.data.cmd.all  & 0xff;
    reply_a->digit_data.byte34.byte_data = (optical_write_data.data.cmd.all >> 8) & 0xff;

    reply_a->digit_data.byte35.bit_data.bit0 = control_station.alive_control_station[CONTROL_STATION_VPU_CAN];
    reply_a->digit_data.byte35.bit_data.bit1 = control_station.active_control_station[CONTROL_STATION_VPU_CAN];

    reply_a->digit_data.byte35.bit_data.bit2 = edrk.auto_master_slave.local.bits.master;
    reply_a->digit_data.byte35.bit_data.bit3 = edrk.auto_master_slave.local.bits.slave;
    reply_a->digit_data.byte35.bit_data.bit4 = edrk.auto_master_slave.local.bits.try_master;

    reply_a->digit_data.byte35.bit_data.bit5 = edrk.auto_master_slave.remoute.bits.master;
    reply_a->digit_data.byte35.bit_data.bit6 = edrk.auto_master_slave.remoute.bits.slave;
    reply_a->digit_data.byte35.bit_data.bit7 = edrk.auto_master_slave.remoute.bits.try_master;

    reply_a->digit_data.byte36.bit_data.bit0 = edrk.Status_Ready.bits.MasterSlaveActive;
    reply_a->digit_data.byte36.bit_data.bit1 = edrk.ms.ready1;
    reply_a->digit_data.byte36.bit_data.bit2 = edrk.ms.ready2;
    reply_a->digit_data.byte36.bit_data.bit3 = edrk.flag_wait_both_ready2;
    reply_a->digit_data.byte36.bit_data.bit4 = edrk.Ready1_another_bs;
    reply_a->digit_data.byte36.bit_data.bit5 = edrk.Ready2_another_bs;
    reply_a->digit_data.byte36.bit_data.bit6 = edrk.flag_another_bs_first_ready12;
    reply_a->digit_data.byte36.bit_data.bit7 = edrk.flag_this_bs_first_ready12;




    reply_a->digit_data.byte37.byte_data = edrk.errors.e8.all  & 0xff;
    reply_a->digit_data.byte38.byte_data = (edrk.errors.e8.all >> 8)  & 0xff;

    reply_a->digit_data.byte39.bit_data.bit0 = edrk.RazborNotFinish;
    reply_a->digit_data.byte39.bit_data.bit1 = edrk.RunZahvatRascepitel;
    reply_a->digit_data.byte39.bit_data.bit2 = edrk.RunUnZahvatRascepitel;
    reply_a->digit_data.byte39.bit_data.bit3 = edrk.Run_Rascepitel;
    reply_a->digit_data.byte39.bit_data.bit4 = edrk.ms.ready3;

    reply_a->digit_data.byte39.bit_data.bit5 = edrk.StartGEDfromZadanie;
    reply_a->digit_data.byte39.bit_data.bit6 = edrk.flag_wait_set_to_zero_zadanie;
    reply_a->digit_data.byte39.bit_data.bit7 = edrk.flag_block_zadanie;
    reply_a->digit_data.byte40.bit_data.bit0 = edrk.you_can_on_rascepitel;
    reply_a->digit_data.byte40.bit_data.bit1 = edrk.StartGEDfromControl;
    reply_a->digit_data.byte40.bit_data.bit2 = edrk.StartGED;
    reply_a->digit_data.byte40.bit_data.bit3 = edrk.GoWait;

    reply_a->digit_data.byte40.bit_data.bit4 = edrk.stop_logs_rs232;
    reply_a->digit_data.byte40.bit_data.bit5 = edrk.stop_slow_log;

    reply_a->digit_data.byte40.bit_data.bit6 = edrk.disable_limit_power_from_svu;
    reply_a->digit_data.byte40.bit_data.bit7 = edrk.disable_uom;

    reply_a->digit_data.byte41.byte_data = edrk.errors.e9.all  & 0xff;
    reply_a->digit_data.byte42.byte_data = (edrk.errors.e9.all >> 8)  & 0xff;

    reply_a->digit_data.byte43.byte_data = edrk.errors.e10.all  & 0xff;
    reply_a->digit_data.byte44.byte_data = (edrk.errors.e10.all >> 8)  & 0xff;

    reply_a->digit_data.byte45.byte_data = edrk.errors.e11.all  & 0xff;
    reply_a->digit_data.byte46.byte_data = (edrk.errors.e11.all >> 8)  & 0xff;

    reply_a->digit_data.byte47.byte_data = edrk.errors.e12.all  & 0xff;
    reply_a->digit_data.byte48.byte_data = (edrk.errors.e12.all >> 8)  & 0xff;


//    reply_a->digit_data.byte49.byte_data = 0;
//    reply_a->digit_data.byte50.byte_data = 0;
    //    reply_a->digit_data.byte49.byte_data = 0;

    //    reply_a->digit_data.byte49.bit_data.bit0 = edrk.from_ing1.bits.ALL_KNOPKA_AVARIA;
    //    reply_a->digit_data.byte49.bit_data.bit0 = edrk.from_ing1.bits.BLOCK_IZOL_AVARIA;
    //    reply_a->digit_data.byte49.bit_data.bit0 = edrk.from_ing1.bits.BLOCK_IZOL_NORMA;
        reply_a->digit_data.byte49.bit_data.bit0 = edrk.from_ing1.bits.LOCAL_REMOUTE;
    //    reply_a->digit_data.byte49.bit_data.bit0 = edrk.from_ing1.bits.NAGREV_ON          = !FROM_ING_NAGREV_ON;
    //    reply_a->digit_data.byte49.bit_data.bit0 = edrk.from_ing1.bits.NASOS_NORMA        = !FROM_ING_NASOS_NORMA;
    //    reply_a->digit_data.byte49.bit_data.bit0 = edrk.from_ing1.bits.NASOS_ON           = !FROM_ING_NASOS_ON;
    //    reply_a->digit_data.byte49.bit_data.bit0 = edrk.from_ing1.bits.OHLAD_UTE4KA_WATER = !FROM_ING_OHLAD_UTE4KA_WATER;
    //    edrk.from_ing1.bits.UPC_24V_NORMA      = !FROM_ING_UPC_24V_NORMA;
        //edrk.from_ing1.bits.OP_PIT_NORMA       = !FROM_ING_OP_PIT_NORMA;
        //edrk.from_ing1.bits.VENTIL_ON          = !FROM_ING_VENTIL_ON;
    //    edrk.from_ing1.bits.VIPR_PREDOHR_NORMA = !FROM_ING_VIPR_PREDOHR_NORMA;

    //    edrk.from_ing1.bits.ZARYAD_ON          = !FROM_ING_ZARYAD_ON;
    //    edrk.from_ing1.bits.ZAZEML_OFF         = !FROM_ING_ZAZEML_OFF;
    //    edrk.from_ing1.bits.ZAZEML_ON          = !FROM_ING_ZAZEML_ON;

        reply_a->digit_data.byte49.bit_data.bit1 = edrk.from_ing2.bits.KEY_MINUS;
        reply_a->digit_data.byte49.bit_data.bit2 = edrk.from_ing2.bits.KEY_PLUS;
        reply_a->digit_data.byte49.bit_data.bit3 = edrk.from_ing2.bits.KEY_KVITIR;

        reply_a->digit_data.byte49.bit_data.bit4 = edrk.from_ing2.bits.KEY_SBOR;
        reply_a->digit_data.byte49.bit_data.bit5 = edrk.from_ing2.bits.KEY_RAZBOR;

    //    edrk.from_ing1.bits.RASCEPITEL_ON      = FROM_ING_RASCEPITEL_ON_OFF;

        reply_a->digit_data.byte49.bit_data.bit6 = edrk.from_ing2.bits.SOST_ZAMKA;
        reply_a->digit_data.byte49.bit_data.bit7 = edrk.from_shema_filter.bits.RAZBOR_SHEMA;
        //
        reply_a->digit_data.byte50.bit_data.bit0 = edrk.from_shema_filter.bits.SBOR_SHEMA;

        reply_a->digit_data.byte50.bit_data.bit1 = edrk.from_shema_filter.bits.ZADA_DISPLAY;
        reply_a->digit_data.byte50.bit_data.bit2 = edrk.from_shema_filter.bits.SVU;
    //  edrk.from_shema.bits.KNOPKA_AVARIA     = FROM_ALL_KNOPKA_AVARIA;
        reply_a->digit_data.byte50.bit_data.bit3 = edrk.from_shema.bits.QTV_ON_OFF;
        reply_a->digit_data.byte50.bit_data.bit4 = edrk.from_shema_filter.bits.UMP_ON_OFF;
        reply_a->digit_data.byte50.bit_data.bit5 = edrk.from_shema_filter.bits.READY_UMP;
        reply_a->digit_data.byte50.bit_data.bit6 = edrk.from_shema.bits.SVU_BLOCK_QTV;
        reply_a->digit_data.byte50.bit_data.bit7 = edrk.errors_another_bs_from_can;


    //    reply_a->digit_data.byte44.byte_data = 0;


        reply_a->digit_data.byte51.bit_data.bit0 = inc_sensor.break_sensor1;
        reply_a->digit_data.byte51.bit_data.bit1 = inc_sensor.break_sensor2;
        reply_a->digit_data.byte51.bit_data.bit2 = pll1.output.flag_find_pll;
        reply_a->digit_data.byte51.bit_data.bit3 = log_params.stop_log_slow;
        reply_a->digit_data.byte51.bit_data.bit4 = log_params.stop_log_level_1;
        reply_a->digit_data.byte51.bit_data.bit5 = log_params.stop_log_level_2;
        reply_a->digit_data.byte51.bit_data.bit6 = log_params.stop_log_slow_level_1;
        reply_a->digit_data.byte51.bit_data.bit7 = log_params.stop_log_slow_level_2;



        reply_a->digit_data.byte52.bit_data.bit0 = edrk.from_zadat4ik.bits.KVITIR;
        reply_a->digit_data.byte52.bit_data.bit1 = edrk.from_zadat4ik.bits.PLUS;
        reply_a->digit_data.byte52.bit_data.bit2 = edrk.from_zadat4ik.bits.MINUS;
        reply_a->digit_data.byte52.bit_data.bit3 = edrk.from_zadat4ik.bits.PROVOROT;
        reply_a->digit_data.byte52.bit_data.bit4 = edrk.from_zadat4ik.bits.UOM_READY_ACTIVE;
        reply_a->digit_data.byte52.bit_data.bit5 = edrk.from_zadat4ik.bits.UOM_LIMIT_3;
        reply_a->digit_data.byte52.bit_data.bit6 = edrk.from_zadat4ik.bits.UOM_LIMIT_2;
        reply_a->digit_data.byte52.bit_data.bit7 = edrk.from_zadat4ik.bits.UOM_LIMIT_1;



        reply_a->digit_data.byte53.bit_data.bit0 = edrk.Run_UMP;
        reply_a->digit_data.byte53.bit_data.bit1 = edrk.Status_UMP_Ok;
        reply_a->digit_data.byte53.bit_data.bit2 = edrk.Zaryad_UMP_Ok;
        reply_a->digit_data.byte53.bit_data.bit3 = edrk.cmd_to_ump;
        reply_a->digit_data.byte53.bit_data.bit4 = edrk.sbor_wait_ump1;
        reply_a->digit_data.byte53.bit_data.bit5 = edrk.sbor_wait_ump2;
        reply_a->digit_data.byte53.bit_data.bit6 = edrk.flag_enable_on_ump;

        reply_a->digit_data.byte53.bit_data.bit7 = edrk.local_ump_on_off;
        reply_a->digit_data.byte54.bit_data.bit0 = edrk.local_ready_ump;

///
        reply_a->digit_data.byte54.bit_data.bit1 = (modbus_table_can_in[128].all) ? 1 : 0; //cmd_local_charge PCH 0
        reply_a->digit_data.byte54.bit_data.bit2 = (modbus_table_can_in[131].all) ? 1 : 0; //cmd_local_uncharge PCH 0

        reply_a->digit_data.byte54.bit_data.bit3 = (modbus_table_can_in[129].all) ? 1 : 0; //cmd_local_charge PCH 1
        reply_a->digit_data.byte54.bit_data.bit4 = (modbus_table_can_in[132].all) ? 1 : 0; //cmd_local_uncharge PCH 1

        reply_a->digit_data.byte54.bit_data.bit5 = edrk.from_shema_filter.bits.UMP_ON_OFF;
        reply_a->digit_data.byte54.bit_data.bit6 = edrk.SumSbor;

        reply_a->digit_data.byte55.bit_data.bit0 = edrk.power_limit.bits.limit_Iout;
        reply_a->digit_data.byte55.bit_data.bit1 = edrk.power_limit.bits.limit_UOM;
        reply_a->digit_data.byte55.bit_data.bit2 = edrk.power_limit.bits.limit_by_temper;
        reply_a->digit_data.byte55.bit_data.bit3 = edrk.power_limit.bits.limit_from_SVU;
        reply_a->digit_data.byte55.bit_data.bit4 = edrk.power_limit.bits.limit_from_uom_fast;
        reply_a->digit_data.byte55.bit_data.bit5 = edrk.power_limit.bits.limit_from_freq;
        reply_a->digit_data.byte55.bit_data.bit6 = edrk.power_limit.bits.limit_moment;
        reply_a->digit_data.byte55.bit_data.bit7 = simple_scalar1.flag_decr_mzz_power;


        reply_a->digit_data.byte56.bit_data.bit0 = (edrk.pult_cmd.log_what_memory & 0x1) ? 1 : 0;
        reply_a->digit_data.byte56.bit_data.bit1 = (edrk.pult_cmd.log_what_memory & 0x2) ? 1 : 0;

        reply_a->digit_data.byte56.bit_data.bit2 = edrk.pult_data.flagSaveDataMoto ? 1 : 0;

        reply_a->digit_data.byte56.bit_data.bit3 = (edrk.pult_data.flagSaveSlowLogs) ? 1 : 0;
        reply_a->digit_data.byte56.bit_data.bit4 = edrk.pult_cmd.send_log ? 1 : 0;

        reply_a->digit_data.byte56.bit_data.bit5 = (log_to_HMI.send_log==1) ? 1 : 0;
        reply_a->digit_data.byte56.bit_data.bit6 = (log_to_HMI.send_log==2) ? 1 : 0;
        reply_a->digit_data.byte56.bit_data.bit7 = (log_to_HMI.send_log==3) ? 1 : 0;

//
        reply_a->digit_data.byte57.bit_data.bit0 = (edrk.break_tempers[0] > ABNORMAL_TEMPER_BREAK_INT) ? 1 : 0;
        reply_a->digit_data.byte57.bit_data.bit1 = (edrk.break_tempers[1] > ABNORMAL_TEMPER_BREAK_INT) ? 1 : 0;
        reply_a->digit_data.byte57.bit_data.bit2 = (edrk.break_tempers[2] > ABNORMAL_TEMPER_BREAK_INT) ? 1 : 0;
        reply_a->digit_data.byte57.bit_data.bit3 = (edrk.break_tempers[3] > ABNORMAL_TEMPER_BREAK_INT) ? 1 : 0;

        reply_a->digit_data.byte57.bit_data.bit4 = (edrk.break_tempers[0] > ALARM_TEMPER_BREAK_INT) ? 1 : 0;
        reply_a->digit_data.byte57.bit_data.bit5 = (edrk.break_tempers[1] > ALARM_TEMPER_BREAK_INT) ? 1 : 0;
        reply_a->digit_data.byte57.bit_data.bit6 = (edrk.break_tempers[2] > ALARM_TEMPER_BREAK_INT) ? 1 : 0;
        reply_a->digit_data.byte57.bit_data.bit7 = (edrk.break_tempers[3] > ALARM_TEMPER_BREAK_INT) ? 1 : 0;

        reply_a->digit_data.byte58.bit_data.bit0 = (edrk.breaker_on==1) ? 1 : 0;

        reply_a->digit_data.byte58.bit_data.bit1 = edrk.warnings.e9.bits.BREAK_TEMPER_WARNING;
        reply_a->digit_data.byte58.bit_data.bit2 = edrk.warnings.e9.bits.BREAK_TEMPER_ALARM;
        reply_a->digit_data.byte58.bit_data.bit3 = edrk.warnings.e9.bits.BREAKER_GED_ON;



//        reply_a->digit_data.byte57.byte_data = 0;//(((unsigned long)edrk.canes_reg>>16) & 0x0ff);
//        reply_a->digit_data.byte58.byte_data = 0;//(((unsigned long)edrk.canes_reg) & 0x3f);
        reply_a->digit_data.byte59.byte_data = 0;//(((unsigned long)edrk.canes_reg>>24) & 0x1);
        reply_a->digit_data.byte60.byte_data = 0;




        return;
}


