#include "DSP281x_Examples.h"   // DSP281x Examples Include File
#include "DSP281x_Device.h"     // DSP281x Headerfile Include File

#include <adc_tools.h>
#include <control_station_project.h>
#include <detect_errors_adc.h>
#include <edrk_main.h>
#include <master_slave.h>
#include <optical_bus.h>
#include <params.h>
#include <params_norma.h>
#include <protect_levels.h>
#include <v_rotor.h>
#include <v_rotor.h>
#include "math.h"
#include "control_station.h"
#include "CAN_Setup.h"
#include "modbus_table_v2.h"
#include "mathlib.h"

void update_errors_to_svu(void);
void update_protect_levels_to_MPU(void);

void update_svu_modbus_table(void)
{
    int current_active_control;

    modbus_table_can_out[0].all = edrk.Stop ? 7 :
//                                  edrk.Provorot ? 6 :
                                  edrk.Go ? 5 :
                                  edrk.Status_Ready.bits.ready_final ? 4 :
                                  edrk.to_ing.bits.RASCEPITEL_ON ? 3 :
                                  edrk.SumSbor ? 2 :
                                  edrk.Status_Ready.bits.ready1 ? 1 : 0;
    modbus_table_can_out[1].all = edrk.warning;
    modbus_table_can_out[2].all = edrk.overheat;
//    modbus_table_can_out[3].all = Ограничение мощности ГЭД;
//    modbus_table_can_out[4].all = Перегрузка ГЭД;
    modbus_table_can_out[5].all = edrk.Status_Ready.bits.Batt;
    modbus_table_can_out[6].all = edrk.from_ing1.bits.UPC_24V_NORMA | edrk.from_ing1.bits.OP_PIT_NORMA ? 0 : 1;
    modbus_table_can_out[7].all = WRotor.RotorDirectionSlow >= 0 ? 0 : 1;
    modbus_table_can_out[8].all = edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER ||
            edrk.Mode_ScalarVectorUFConst == ALG_MODE_SCALAR_POWER ? 1 : 0;
    current_active_control = get_current_station_control();
    modbus_table_can_out[9].all = current_active_control == CONTROL_STATION_INGETEAM_PULT_RS485 ? 1 :
            current_active_control == CONTROL_STATION_MPU_KEY_CAN || current_active_control == CONTROL_STATION_MPU_KEY_RS485 ? 2 :
            current_active_control == CONTROL_STATION_ZADATCHIK_CAN ? 3 :
            current_active_control == CONTROL_STATION_VPU_CAN ? 4 :
            current_active_control == CONTROL_STATION_MPU_SVU_CAN || current_active_control == CONTROL_STATION_MPU_SVU_RS485 ? 5 :
            0;
    modbus_table_can_out[10].all = edrk.errors.e2.bits.T_UO1_MAX || edrk.errors.e6.bits.UO1_KEYS ? 3 :
                                    edrk.warnings.e2.bits.T_UO1_MAX ? 2 : 1;
    modbus_table_can_out[11].all = edrk.errors.e2.bits.T_UO2_MAX || edrk.errors.e6.bits.UO2_KEYS ? 3 :
                                        edrk.warnings.e2.bits.T_UO2_MAX ? 2 : 1;
    modbus_table_can_out[12].all = edrk.errors.e2.bits.T_UO3_MAX || edrk.errors.e6.bits.UO3_KEYS ? 3 :
                                        edrk.warnings.e2.bits.T_UO3_MAX ? 2 : 1;
    modbus_table_can_out[13].all = edrk.errors.e2.bits.T_UO4_MAX || edrk.errors.e6.bits.UO4_KEYS ? 3 :
                                        edrk.warnings.e2.bits.T_UO4_MAX ? 2 : 1;
    modbus_table_can_out[14].all = edrk.errors.e2.bits.T_UO5_MAX || edrk.errors.e6.bits.UO5_KEYS ? 3 :
                                        edrk.warnings.e2.bits.T_UO5_MAX ? 2 : 1;
    modbus_table_can_out[15].all = edrk.errors.e2.bits.T_UO6_MAX || edrk.errors.e6.bits.UO6_KEYS ? 3 :
                                        edrk.warnings.e2.bits.T_UO6_MAX ? 2 : 1;
    modbus_table_can_out[16].all = edrk.errors.e2.bits.T_UO7_MAX || edrk.errors.e6.bits.UO7_KEYS ? 3 :
                                        edrk.warnings.e2.bits.T_UO7_MAX ? 2 : 1;
    modbus_table_can_out[17].all = edrk.Status_QTV_Ok;// edrk.from_shema.bits.QTV_ON_OFF;
    modbus_table_can_out[18].all = edrk.from_svu.bits.BLOCKED;
    modbus_table_can_out[19].all = edrk.from_shema_filter.bits.UMP_ON_OFF;
    modbus_table_can_out[20].all = edrk.from_shema_filter.bits.READY_UMP;
    modbus_table_can_out[21].all = edrk.from_ing1.bits.RASCEPITEL_ON;
    modbus_table_can_out[22].all = edrk.from_ing1.bits.UPC_24V_NORMA;
    modbus_table_can_out[23].all = edrk.from_ing1.bits.OHLAD_UTE4KA_WATER;
    modbus_table_can_out[24].all = edrk.from_ing2.bits.SOST_ZAMKA;
    modbus_table_can_out[25].all = edrk.from_ing1.bits.ZARYAD_ON | edrk.from_shema_filter.bits.UMP_ON_OFF; //Видимо, заряда от внутреннего УМП не будет, добавил УМП намагничивания
    modbus_table_can_out[26].all = edrk.from_ing1.bits.VENTIL_ON;
    modbus_table_can_out[27].all = edrk.to_ing.bits.NASOS_1_ON == 1 && edrk.from_ing1.bits.NASOS_ON == 1 ? 1 : 0;
    modbus_table_can_out[28].all = edrk.to_ing.bits.NASOS_2_ON == 1 && edrk.from_ing1.bits.NASOS_ON == 1 ? 1 : 0;
    modbus_table_can_out[29].all = edrk.from_ing1.bits.NASOS_NORMA;
    modbus_table_can_out[30].all = edrk.from_ing1.bits.ZAZEML_ON;
    modbus_table_can_out[31].all = edrk.from_ing1.bits.NAGREV_ON;
    modbus_table_can_out[32].all = edrk.from_ing1.bits.BLOCK_IZOL_NORMA == 1 ? 1 : 0;
    modbus_table_can_out[33].all = edrk.errors.e5.bits.ERROR_ISOLATE == 0 && edrk.from_ing1.bits.BLOCK_IZOL_NORMA == 1 ? 0 : 1;
    modbus_table_can_out[34].all = edrk.from_ing1.bits.ALL_KNOPKA_AVARIA;

    if (edrk.MasterSlave == MODE_MASTER)
        modbus_table_can_out[35].all = 1;
    else
    if (edrk.MasterSlave == MODE_SLAVE)
        modbus_table_can_out[35].all = 0;
    else
        modbus_table_can_out[35].all = 2; // MODE_DONTKNOW

//    modbus_table_can_out[35].all = edrk.MasterSlave == MODE_MASTER ? 1 : 0;
    modbus_table_can_out[36].all = edrk.from_ing1.bits.OP_PIT_NORMA & edrk.from_ing1.bits.UPC_24V_NORMA;
    modbus_table_can_out[37].all = optical_read_data.status == 1 && optical_write_data.status == 1 ? 1 : 0;
    modbus_table_can_out[38].all = edrk.warnings.e7.bits.MASTER_SLAVE_SYNC == 0 ? 1 : 0;
    modbus_table_can_out[39].all = fast_round(_IQtoF(filter.iqIm) * NORMA_ACP);
    modbus_table_can_out[40].all = fast_round(_IQtoF(filter.iqIin_sum) * NORMA_ACP);
    modbus_table_can_out[41].all = fast_round(_IQtoF(filter.iqU_1_long + filter.iqU_2_long) * NORMA_ACP);

    if (filter.iqUin_m1>=filter.iqUin_m2)
        modbus_table_can_out[42].all = fast_round(_IQtoF(filter.iqUin_m1) * NORMA_ACP / 1.41);
    else
        modbus_table_can_out[42].all = fast_round(_IQtoF(filter.iqUin_m2) * NORMA_ACP / 1.41);

    modbus_table_can_out[43].all = fast_round(_IQtoF(filter.iqU_1_long) * NORMA_ACP);
    modbus_table_can_out[44].all = fast_round(_IQtoF(filter.iqU_2_long) * NORMA_ACP);
    modbus_table_can_out[45].all = fast_round(_IQtoF(filter.iqIm_1) * NORMA_ACP / 1.41);
    modbus_table_can_out[46].all = fast_round(_IQtoF(filter.iqIm_1) * NORMA_ACP / 1.41);
    modbus_table_can_out[47].all = fast_round(_IQtoF(filter.iqIm_1) * NORMA_ACP / 1.41);
    modbus_table_can_out[48].all = fast_round(_IQtoF(filter.iqIm_2) * NORMA_ACP / 1.41);
    modbus_table_can_out[49].all = fast_round(_IQtoF(filter.iqIm_2) * NORMA_ACP / 1.41);
    modbus_table_can_out[50].all = fast_round(_IQtoF(filter.iqIm_2) * NORMA_ACP / 1.41);
    modbus_table_can_out[51].all = fast_round(_IQtoF(filter.iqIin_sum) * NORMA_ACP);
//    modbus_table_can_out[52].all = Uvh rms
//    modbus_table_can_out[53].all =
//    modbus_table_can_out[54].all =
//    modbus_table_can_out[55].all =
    modbus_table_can_out[56].all = _IQtoF(analog.iqIbreak_1) * NORMA_ACP;
    modbus_table_can_out[57].all = _IQtoF(analog.iqIbreak_2) * NORMA_ACP;

    //Temperatures
    modbus_table_can_out[58].all = fast_round(edrk.temper_edrk.real_temper_u[0]);
    modbus_table_can_out[59].all = fast_round(edrk.temper_edrk.real_temper_u[1]);
    modbus_table_can_out[60].all = fast_round(edrk.temper_edrk.real_temper_u[2]);
    modbus_table_can_out[61].all = fast_round(edrk.temper_edrk.real_temper_u[3]);
    modbus_table_can_out[62].all = fast_round(edrk.temper_edrk.real_temper_u[4]);
    modbus_table_can_out[63].all = fast_round(edrk.temper_edrk.real_temper_u[5]);
    modbus_table_can_out[64].all = fast_round(edrk.temper_edrk.real_temper_u[6]);
    modbus_table_can_out[65].all = fast_round(edrk.temper_edrk.real_temper_water[1]);
    modbus_table_can_out[66].all = fast_round(edrk.temper_edrk.real_temper_water[0]);
    modbus_table_can_out[67].all = fast_round(edrk.temper_edrk.real_temper_air[0]);
    modbus_table_can_out[68].all = fast_round(edrk.temper_edrk.real_temper_air[1]);
    modbus_table_can_out[69].all = fast_round(edrk.temper_edrk.real_temper_air[2]);
    modbus_table_can_out[70].all = fast_round(edrk.temper_edrk.real_temper_air[3]);

    modbus_table_can_out[71].all = fast_round(edrk.p_water_edrk.real_p_water[0]);

    modbus_table_can_out[72].all = fast_round(_IQtoF(edrk.zadanie.iq_oborots_zad_hz_rmp) * NORMA_FROTOR * 60);
    modbus_table_can_out[73].all = edrk.oborots;//  fast_round(_IQtoF(WRotor.iqWRotorSumFilter3) * NORMA_FROTOR * 60);
    modbus_table_can_out[74].all = edrk.oborots;//fast_round(_IQtoF(WRotor.iqWRotorSumFilter3) * NORMA_FROTOR * 60); //Sensor 1
    modbus_table_can_out[75].all = edrk.oborots;//fast_round(_IQtoF(WRotor.iqWRotorSumFilter3) * NORMA_FROTOR * 60); //Sensor 1

    modbus_table_can_out[76].all = fast_round(_IQtoF(edrk.zadanie.iq_power_zad_rmp) * NORMA_ACP * NORMA_ACP / 1000.0);
    modbus_table_can_out[77].all = fabs(edrk.power_kw);//  fast_round(_IQtoF(filter.PowerScalar) * NORMA_ACP* NORMA_ACP / 1000.0);

    modbus_table_can_out[78].all = fast_round(edrk.temper_acdrive.winding.filter_real_temper[0]);
    modbus_table_can_out[79].all = fast_round(edrk.temper_acdrive.winding.filter_real_temper[1]);
    modbus_table_can_out[80].all = fast_round(edrk.temper_acdrive.winding.filter_real_temper[2]);
    modbus_table_can_out[81].all = fast_round(edrk.temper_acdrive.winding.filter_real_temper[3]);
    modbus_table_can_out[82].all = fast_round(edrk.temper_acdrive.winding.filter_real_temper[4]);
    modbus_table_can_out[83].all = fast_round(edrk.temper_acdrive.winding.filter_real_temper[5]);
    modbus_table_can_out[84].all = fast_round(edrk.temper_acdrive.bear.filter_real_temper[0]); //Приводная сторона TODO: проверить соответствие
    modbus_table_can_out[85].all = fast_round(edrk.temper_acdrive.bear.filter_real_temper[1]); //Неприводная сторона

    modbus_table_can_out[86].all = Unites[UMU_CAN_DEVICE][24];
    modbus_table_can_out[87].all = Unites[UMU_CAN_DEVICE][25];
    modbus_table_can_out[88].all = Unites[UMU_CAN_DEVICE][28];
    modbus_table_can_out[89].all = Unites[UMU_CAN_DEVICE][29];
    modbus_table_can_out[90].all = Unites[UMU_CAN_DEVICE][34];
    modbus_table_can_out[91].all = Unites[UMU_CAN_DEVICE][35];
    modbus_table_can_out[92].all = Unites[UMU_CAN_DEVICE][34]; //Дублировал, нет у Димы
    modbus_table_can_out[93].all = Unites[UMU_CAN_DEVICE][35]; //Дублировал, нет у Димы

    modbus_table_can_out[94].all = edrk.warnings.e2.bits.T_UO1_MAX | edrk.warnings.e2.bits.T_UO2_MAX |
            edrk.warnings.e2.bits.T_UO3_MAX | edrk.warnings.e2.bits.T_UO4_MAX |
            edrk.warnings.e2.bits.T_UO5_MAX | edrk.warnings.e2.bits.T_UO6_MAX |
            edrk.warnings.e2.bits.T_UO7_MAX;
    modbus_table_can_out[95].all = edrk.errors.e2.bits.T_UO1_MAX | edrk.errors.e2.bits.T_UO2_MAX |
            edrk.errors.e2.bits.T_UO3_MAX | edrk.errors.e2.bits.T_UO4_MAX |
            edrk.errors.e2.bits.T_UO5_MAX | edrk.errors.e2.bits.T_UO6_MAX |
            edrk.errors.e2.bits.T_UO7_MAX;
    modbus_table_can_out[96].all = edrk.warnings.e2.bits.T_AIR0_MAX | edrk.warnings.e2.bits.T_AIR1_MAX |
            edrk.warnings.e2.bits.T_AIR2_MAX | edrk.warnings.e2.bits.T_AIR3_MAX;
    modbus_table_can_out[97].all = edrk.errors.e2.bits.T_AIR0_MAX | edrk.errors.e2.bits.T_AIR1_MAX |
            edrk.errors.e2.bits.T_AIR2_MAX | edrk.errors.e2.bits.T_AIR3_MAX;
    modbus_table_can_out[98].all = edrk.warnings.e2.bits.T_WATER_EXT_MAX;
    modbus_table_can_out[99].all = edrk.errors.e2.bits.T_WATER_EXT_MAX;
    modbus_table_can_out[100].all = edrk.warnings.e2.bits.T_WATER_INT_MAX;
    modbus_table_can_out[101].all = edrk.errors.e2.bits.T_WATER_INT_MAX;

    modbus_table_can_out[102].all = edrk.warnings.e2.bits.P_WATER_INT_MAX;
    modbus_table_can_out[103].all = edrk.errors.e2.bits.P_WATER_INT_MAX;
    modbus_table_can_out[104].all = edrk.warnings.e2.bits.P_WATER_INT_MIN;
    modbus_table_can_out[105].all = edrk.errors.e2.bits.P_WATER_INT_MIN;

    modbus_table_can_out[106].all = edrk.warnings.e7.bits.T_ACDRIVE_WINDING_MAX;
    modbus_table_can_out[107].all = edrk.errors.e7.bits.T_ACDRIVE_WINDING_MAX;
    modbus_table_can_out[108].all = edrk.warnings.e7.bits.T_ACDRIVE_BEAR_MAX_DNE; //Температура подшипника
    modbus_table_can_out[109].all = edrk.errors.e7.bits.T_ACDRIVE_BEAR_MAX_DNE;
    modbus_table_can_out[110].all = edrk.warnings.e9.bits.T_ACDRIVE_BEAR_MAX_NE; //Проверить приводной и не приводной
    modbus_table_can_out[111].all = edrk.errors.e9.bits.T_ACDRIVE_BEAR_MAX_NE;

    modbus_table_can_out[112].all = edrk.warnings.e9.bits.I_GED_MAX;
    modbus_table_can_out[113].all = edrk.errors.e1.bits.I_UO2_MAX | edrk.errors.e1.bits.I_UO3_MAX |
            edrk.errors.e1.bits.I_UO4_MAX | edrk.errors.e1.bits.I_UO5_MAX |
            edrk.errors.e1.bits.I_UO6_MAX | edrk.errors.e1.bits.I_UO7_MAX;  //TODO add adc errors
    modbus_table_can_out[114].all = edrk.errors.e0.bits.I_1_MAX | edrk.errors.e0.bits.I_2_MAX;
    modbus_table_can_out[115].all = edrk.errors.e0.bits.U_1_MAX | edrk.errors.e0.bits.U_2_MAX;
    modbus_table_can_out[116].all = edrk.warnings.e0.bits.U_IN_MIN;
    modbus_table_can_out[117].all = edrk.errors.e0.bits.U_IN_MIN;
    modbus_table_can_out[118].all = edrk.warnings.e0.bits.U_IN_MAX;
    modbus_table_can_out[119].all = edrk.errors.e0.bits.U_IN_MAX;
    modbus_table_can_out[120].all = edrk.warnings.e9.bits.SENSOR_ROTOR_1_BREAK; //TODO неисправность датчика оборотов
    modbus_table_can_out[121].all = edrk.warnings.e9.bits.SENSOR_ROTOR_2_BREAK; //TODO превышение допустимых оборотов
    modbus_table_can_out[122].all = edrk.Kvitir;


    modbus_table_can_out[137].all = edrk.pult_data.data_from_pult.moto[15];
    modbus_table_can_out[138].all = edrk.pult_data.data_from_pult.moto[6];

    update_errors_to_svu();
    update_protect_levels_to_MPU();

    copy_from_can_out_to_rs_out();

}

#define MPU_ADRESS_CMD_START 122 // у нас -1 относительно нио14, 122 соответствует 123 у нио14
#define MPU_ADRESS_CMD_END   144 //138 //

#if (MPU_ADRESS_CMD_END>=SIZE_MODBUS_TABLE)
#define MPU_ADRESS_CMD_END  (SIZE_MODBUS_TABLE-1)
#endif


#if (MPU_ADRESS_CMD_END - MPU_ADRESS_CMD_START +1 )>CONTROL_STATION_MAX_RAW_DATA
#define MPU_LENGTH_CMD  CONTROL_STATION_MAX_RAW_DATA
#else
#define MPU_LENGTH_CMD  (MPU_ADRESS_CMD_END - MPU_ADRESS_CMD_START + 1)
#endif
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////

void unpack_answer_from_MPU_SVU_CAN_filter(unsigned int cc)
{
    unsigned int i = 0, j = 0, k, max_data;

    for (i = 0; i < MPU_LENGTH_CMD; i++)
    {
        max_data = 0;//control_station.raw_array_data_temp[cc][i][0].all;
        //min_data = 0;//control_station.raw_array_data_temp[cc][i][0].all;

        for (j=0; j<CONTROL_STATION_MAX_RAW_DATA_TEMP; j++)
        {
            if (control_station.raw_array_data_temp[cc][i][j].all > max_data)
                max_data =  control_station.raw_array_data_temp[cc][i][j].all;
        }

        control_station.raw_array_data[cc][i].all = max_data;

    }

}

//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////


void unpack_answer_from_MPU_SVU_CAN(unsigned int cc) {
    int i = 0, j = 0, k;
//    static unsigned int prev_CAN_count_cycle_input_units = 0;

    if (control_station.prev_CAN_count_cycle_input_units[cc] != mpu_can_setup.CAN_count_cycle_input_units[0])
    {
        k = control_station.count_raw_array_data_temp[cc];
        for (i = 0, j = 0; i < MPU_LENGTH_CMD && j < CONTROL_STATION_MAX_RAW_DATA; i++, j++)
        {
                    control_station.raw_array_data_temp[cc][j][k].all = modbus_table_can_in[MPU_ADRESS_CMD_START+i].all;
        }

        control_station.count_raw_array_data_temp[cc]++;
        if (control_station.count_raw_array_data_temp[cc]>=CONTROL_STATION_MAX_RAW_DATA_TEMP)
            control_station.count_raw_array_data_temp[cc] = 0;

        control_station.prev_CAN_count_cycle_input_units[cc] = mpu_can_setup.CAN_count_cycle_input_units[0];
    }


//    for (i = ADRESS_CMD_START, j = 0; i < SIZE_MODBUS_TABLE && j < CONTROL_STATION_MAX_RAW_DATA; i++, j++)
//    {
//            control_station.raw_array_data[cc][j].all = modbus_table_can_in[i].all;
//    }

    unpack_answer_from_MPU_SVU_CAN_filter(cc);

}

void unpack_answer_from_MPU_SVU_RS(unsigned int cc) {
    int i = 0, j = 0;
    for (i = MPU_ADRESS_CMD_START, j = 0; i < SIZE_MODBUS_TABLE && j < CONTROL_STATION_MAX_RAW_DATA; i++, j++)
            control_station.raw_array_data[cc][j].all = modbus_table_rs_in[i].all;
}

void update_errors_to_svu() {
    modbus_table_can_out[208].bit.bit0 = project.cds_tk[0].read.sbus.status_protect_current_ack.bit.tk0_ack;
    modbus_table_can_out[208].bit.bit1 = project.cds_tk[0].read.sbus.status_protect_current_ack.bit.tk1_ack;
    modbus_table_can_out[208].bit.bit2 = project.cds_tk[0].read.sbus.status_protect_current_ack.bit.tk2_ack;
    modbus_table_can_out[208].bit.bit3 = project.cds_tk[0].read.sbus.status_protect_current_ack.bit.tk3_ack;
    modbus_table_can_out[208].bit.bit4 = project.cds_tk[0].read.sbus.status_protect_current_ack.bit.tk4_ack;
    modbus_table_can_out[208].bit.bit5 = project.cds_tk[0].read.sbus.status_protect_current_ack.bit.tk5_ack;
    modbus_table_can_out[208].bit.bit6 = project.cds_tk[0].read.sbus.status_protect_current_ack.bit.tk6_ack;
    modbus_table_can_out[208].bit.bit7 = project.cds_tk[0].read.sbus.status_protect_current_ack.bit.tk7_ack;

    modbus_table_can_out[208].bit.bit8 = project.cds_tk[1].read.sbus.status_protect_current_ack.bit.tk0_ack;
    modbus_table_can_out[208].bit.bit9 = project.cds_tk[1].read.sbus.status_protect_current_ack.bit.tk1_ack;
    modbus_table_can_out[208].bit.bit10 = project.cds_tk[1].read.sbus.status_protect_current_ack.bit.tk2_ack;
    modbus_table_can_out[208].bit.bit11 = project.cds_tk[1].read.sbus.status_protect_current_ack.bit.tk3_ack;
    modbus_table_can_out[208].bit.bit12 = project.cds_tk[1].read.sbus.status_protect_current_ack.bit.tk4_ack;
    modbus_table_can_out[208].bit.bit13 = project.cds_tk[1].read.sbus.status_protect_current_ack.bit.tk5_ack;
    modbus_table_can_out[208].bit.bit14 = project.cds_tk[1].read.sbus.status_protect_current_ack.bit.tk6_ack;
    modbus_table_can_out[208].bit.bit15 = project.cds_tk[1].read.sbus.status_protect_current_ack.bit.tk7_ack;

    modbus_table_can_out[200].bit.bit0 = project.cds_tk[2].read.sbus.status_protect_current_ack.bit.tk0_ack;
    modbus_table_can_out[200].bit.bit1 = project.cds_tk[2].read.sbus.status_protect_current_ack.bit.tk1_ack;
    modbus_table_can_out[200].bit.bit2 = project.cds_tk[2].read.sbus.status_protect_current_ack.bit.tk2_ack;
    modbus_table_can_out[200].bit.bit3 = project.cds_tk[2].read.sbus.status_protect_current_ack.bit.tk3_ack;
    modbus_table_can_out[200].bit.bit4 = project.cds_tk[2].read.sbus.status_protect_current_ack.bit.tk4_ack;
    modbus_table_can_out[200].bit.bit5 = project.cds_tk[2].read.sbus.status_protect_current_ack.bit.tk5_ack;
    modbus_table_can_out[200].bit.bit6 = project.cds_tk[2].read.sbus.status_protect_current_ack.bit.tk6_ack;
    modbus_table_can_out[200].bit.bit7 = project.cds_tk[2].read.sbus.status_protect_current_ack.bit.tk7_ack;
    modbus_table_can_out[200].bit.bit8 = project.cds_tk[3].read.sbus.status_protect_current_ack.bit.tk0_ack;
    modbus_table_can_out[200].bit.bit9 = project.cds_tk[3].read.sbus.status_protect_current_ack.bit.tk1_ack;

    if (edrk.flag_second_PCH == 1) {
        modbus_table_can_out[200].bit.bit10 = edrk.errors.e4.bits.ANOTHER_BS_POWER_OFF;
    } else {
        modbus_table_can_out[200].bit.bit11 = edrk.errors.e4.bits.ANOTHER_BS_POWER_OFF;
    }

    modbus_table_can_out[201].bit.bit0 = project.cds_tk[0].read.sbus.status_protect_current_ack.bit.tk0_current;
    modbus_table_can_out[201].bit.bit1 = project.cds_tk[0].read.sbus.status_protect_current_ack.bit.tk1_current;
    modbus_table_can_out[201].bit.bit2 = project.cds_tk[0].read.sbus.status_protect_current_ack.bit.tk2_current;
    modbus_table_can_out[201].bit.bit3 = project.cds_tk[0].read.sbus.status_protect_current_ack.bit.tk3_current;
    modbus_table_can_out[201].bit.bit4 = project.cds_tk[0].read.sbus.status_protect_current_ack.bit.tk4_current;
    modbus_table_can_out[201].bit.bit5 = project.cds_tk[0].read.sbus.status_protect_current_ack.bit.tk5_current;
    modbus_table_can_out[201].bit.bit6 = project.cds_tk[0].read.sbus.status_protect_current_ack.bit.tk6_current;
    modbus_table_can_out[201].bit.bit7 = project.cds_tk[0].read.sbus.status_protect_current_ack.bit.tk7_current;
    modbus_table_can_out[201].bit.bit8 = project.cds_tk[1].read.sbus.status_protect_current_ack.bit.tk0_current;
    modbus_table_can_out[201].bit.bit9 = project.cds_tk[1].read.sbus.status_protect_current_ack.bit.tk1_current;
    modbus_table_can_out[201].bit.bit10 = project.cds_tk[1].read.sbus.status_protect_current_ack.bit.tk2_current;
    modbus_table_can_out[201].bit.bit11 = project.cds_tk[1].read.sbus.status_protect_current_ack.bit.tk3_current;
    modbus_table_can_out[201].bit.bit12 = project.cds_tk[1].read.sbus.status_protect_current_ack.bit.tk4_current;
    modbus_table_can_out[201].bit.bit13 = project.cds_tk[1].read.sbus.status_protect_current_ack.bit.tk5_current;
    modbus_table_can_out[201].bit.bit14 = project.cds_tk[1].read.sbus.status_protect_current_ack.bit.tk6_current;
    modbus_table_can_out[201].bit.bit15 = project.cds_tk[1].read.sbus.status_protect_current_ack.bit.tk7_current;

    modbus_table_can_out[202].bit.bit0 = project.cds_tk[2].read.sbus.status_protect_current_ack.bit.tk0_current;
    modbus_table_can_out[202].bit.bit1 = project.cds_tk[2].read.sbus.status_protect_current_ack.bit.tk1_current;
    modbus_table_can_out[202].bit.bit2 = project.cds_tk[2].read.sbus.status_protect_current_ack.bit.tk2_current;
    modbus_table_can_out[202].bit.bit3 = project.cds_tk[2].read.sbus.status_protect_current_ack.bit.tk3_current;
    modbus_table_can_out[202].bit.bit4 = project.cds_tk[2].read.sbus.status_protect_current_ack.bit.tk4_current;
    modbus_table_can_out[202].bit.bit5 = project.cds_tk[2].read.sbus.status_protect_current_ack.bit.tk5_current;
    modbus_table_can_out[202].bit.bit6 = project.cds_tk[2].read.sbus.status_protect_current_ack.bit.tk6_current;
    modbus_table_can_out[202].bit.bit7 = project.cds_tk[2].read.sbus.status_protect_current_ack.bit.tk7_current;
    modbus_table_can_out[202].bit.bit8 = project.cds_tk[3].read.sbus.status_protect_current_ack.bit.tk0_current;
    modbus_table_can_out[202].bit.bit9 = project.cds_tk[3].read.sbus.status_protect_current_ack.bit.tk1_current;

    modbus_table_can_out[203].bit.bit0 = project.cds_tk[0].read.sbus.lock_status_error.bit.mintime_err_keys_3210;
    modbus_table_can_out[203].bit.bit1 = project.cds_tk[0].read.sbus.lock_status_error.bit.mintime_err_keys_3210;
    modbus_table_can_out[203].bit.bit2 = project.cds_tk[0].read.sbus.lock_status_error.bit.mintime_err_keys_3210;
    modbus_table_can_out[203].bit.bit3 = project.cds_tk[0].read.sbus.lock_status_error.bit.mintime_err_keys_3210;
    modbus_table_can_out[203].bit.bit4 = project.cds_tk[0].read.sbus.lock_status_error.bit.mintime_err_keys_7654;
    modbus_table_can_out[203].bit.bit5 = project.cds_tk[0].read.sbus.lock_status_error.bit.mintime_err_keys_7654;
    modbus_table_can_out[203].bit.bit6 = project.cds_tk[0].read.sbus.lock_status_error.bit.mintime_err_keys_7654;
    modbus_table_can_out[203].bit.bit7 = project.cds_tk[0].read.sbus.lock_status_error.bit.mintime_err_keys_7654;
    modbus_table_can_out[203].bit.bit8 = project.cds_tk[1].read.sbus.lock_status_error.bit.mintime_err_keys_3210;
    modbus_table_can_out[203].bit.bit9 = project.cds_tk[1].read.sbus.lock_status_error.bit.mintime_err_keys_3210;
    modbus_table_can_out[203].bit.bit10 = project.cds_tk[1].read.sbus.lock_status_error.bit.mintime_err_keys_3210;
    modbus_table_can_out[203].bit.bit11 = project.cds_tk[1].read.sbus.lock_status_error.bit.mintime_err_keys_3210;
    modbus_table_can_out[203].bit.bit12 = project.cds_tk[1].read.sbus.lock_status_error.bit.mintime_err_keys_7654;
    modbus_table_can_out[203].bit.bit13 = project.cds_tk[1].read.sbus.lock_status_error.bit.mintime_err_keys_7654;
    modbus_table_can_out[203].bit.bit14 = project.cds_tk[1].read.sbus.lock_status_error.bit.mintime_err_keys_7654;
    modbus_table_can_out[203].bit.bit15 = project.cds_tk[1].read.sbus.lock_status_error.bit.mintime_err_keys_7654;

    modbus_table_can_out[204].bit.bit0 = project.cds_tk[2].read.sbus.lock_status_error.bit.mintime_err_keys_3210;
    modbus_table_can_out[204].bit.bit1 = project.cds_tk[2].read.sbus.lock_status_error.bit.mintime_err_keys_3210;
    modbus_table_can_out[204].bit.bit2 = project.cds_tk[2].read.sbus.lock_status_error.bit.mintime_err_keys_3210;
    modbus_table_can_out[204].bit.bit3 = project.cds_tk[2].read.sbus.lock_status_error.bit.mintime_err_keys_3210;
    modbus_table_can_out[204].bit.bit4 = project.cds_tk[2].read.sbus.lock_status_error.bit.mintime_err_keys_7654;
    modbus_table_can_out[204].bit.bit5 = project.cds_tk[2].read.sbus.lock_status_error.bit.mintime_err_keys_7654;
    modbus_table_can_out[204].bit.bit6 = project.cds_tk[2].read.sbus.lock_status_error.bit.mintime_err_keys_7654;
    modbus_table_can_out[204].bit.bit7 = project.cds_tk[2].read.sbus.lock_status_error.bit.mintime_err_keys_7654;
    modbus_table_can_out[204].bit.bit8 = project.cds_tk[3].read.sbus.lock_status_error.bit.mintime_err_keys_3210;
    modbus_table_can_out[204].bit.bit9 = project.cds_tk[3].read.sbus.lock_status_error.bit.mintime_err_keys_3210;

    modbus_table_can_out[205].bit.bit0 = edrk.errors.e3.bits.NOT_READY_TK_0;
    modbus_table_can_out[205].bit.bit1 = edrk.errors.e3.bits.NOT_READY_TK_1;
    modbus_table_can_out[205].bit.bit2 = edrk.errors.e3.bits.NOT_READY_TK_2;
    modbus_table_can_out[205].bit.bit3 = edrk.errors.e3.bits.NOT_READY_TK_3;
    modbus_table_can_out[205].bit.bit4 = edrk.errors.e3.bits.NOT_READY_IN_0;
    modbus_table_can_out[205].bit.bit5 = edrk.errors.e3.bits.NOT_READY_IN_1;
    modbus_table_can_out[205].bit.bit6 = edrk.errors.e3.bits.NOT_READY_OUT_0;
    modbus_table_can_out[205].bit.bit7 = edrk.errors.e3.bits.NOT_READY_ADC_0;
    modbus_table_can_out[205].bit.bit8 = edrk.errors.e3.bits.NOT_READY_HWP_0;
    modbus_table_can_out[205].bit.bit9 = edrk.errors.e3.bits.NOT_READY_ADC_1;
    modbus_table_can_out[205].bit.bit10 = edrk.errors.e3.bits.NOT_READY_CONTR;

    modbus_table_can_out[206].bit.bit0 = edrk.errors.e5.bits.KEY_AVARIA;
    modbus_table_can_out[206].bit.bit1 = edrk.errors.e6.bits.QTV_ERROR_NOT_ANSWER;
    modbus_table_can_out[206].bit.bit2 = edrk.errors.e7.bits.SVU_BLOCK_ON_QTV;
    modbus_table_can_out[206].bit.bit3 = edrk.errors.e7.bits.UMP_NOT_ANSWER;
    modbus_table_can_out[206].bit.bit4 = edrk.errors.e7.bits.UMP_NOT_READY;
    modbus_table_can_out[206].bit.bit5 = edrk.errors.e6.bits.RASCEPITEL_ERROR_NOT_ANSWER;
    modbus_table_can_out[206].bit.bit6 = edrk.errors.e7.bits.ANOTHER_RASCEPITEL_ON;
    modbus_table_can_out[206].bit.bit7 = edrk.warnings.e7.bits.AUTO_SET_MASTER;
    modbus_table_can_out[206].bit.bit8 = edrk.errors.e7.bits.ANOTHER_PCH_NOT_ANSWER;
    modbus_table_can_out[206].bit.bit9 = edrk.errors.e8.bits.WDOG_OPTICAL_BUS;
    modbus_table_can_out[206].bit.bit10 = edrk.errors.e6.bits.QTV_ERROR_NOT_ANSWER;    //Нет подтверждение на отключение автомата главного тока
    modbus_table_can_out[206].bit.bit11 = edrk.errors.e1.bits.NO_CONFIRM_ON_RASCEPITEL;    //Нет разрешение от другого БС на подключение расцепителя
    modbus_table_can_out[206].bit.bit12 = edrk.errors.e6.bits.RASCEPITEL_ERROR_NOT_ANSWER;
    modbus_table_can_out[206].bit.bit13 = edrk.errors.e1.bits.ANOTHER_BS_VERY_LONG_WAIT;
    modbus_table_can_out[206].bit.bit14 = edrk.errors.e1.bits.VERY_LONG_BOTH_READY2;
    modbus_table_can_out[206].bit.bit15 = edrk.errors.e1.bits.BOTH_KEYS_CHARGE_DISCHARGE;


    modbus_table_can_out[207].bit.bit0 = !control_station.alive_control_station[CONTROL_STATION_ZADATCHIK_CAN];
    modbus_table_can_out[207].bit.bit1 = !control_station.alive_control_station[CONTROL_STATION_MPU_SVU_CAN];
    modbus_table_can_out[207].bit.bit2 = 0;// CAN_timeout[get_real_in_mbox(UNITS_TYPE_BOX,UMU_CAN_DEVICE)]; Исключён из схемы
    modbus_table_can_out[207].bit.bit3 = CAN_timeout[get_real_in_mbox(UNITS_TYPE_BOX,BKSSD_CAN_DEVICE)];
    modbus_table_can_out[207].bit.bit4 = CAN_timeout[get_real_in_mbox(UNITS_TYPE_BOX,VPU_CAN)];
    modbus_table_can_out[207].bit.bit5 = edrk.warnings.e7.bits.CAN2CAN_BS;
    modbus_table_can_out[207].bit.bit6 = edrk.errors.e7.bits.CAN2CAN_BS;

    if (edrk.flag_second_PCH == 1) {
        modbus_table_can_out[207].bit.bit7 = edrk.warnings.e4.bits.ANOTHER_BS_POWER_OFF;
    } else {
        modbus_table_can_out[207].bit.bit8 = edrk.warnings.e4.bits.ANOTHER_BS_POWER_OFF;
    }
    modbus_table_can_out[207].bit.bit9 = edrk.errors.e7.bits.ANOTHER_BS_ALARM; //аварийное отключение другого БС (оптический канал)
    modbus_table_can_out[207].bit.bit10 = edrk.warnings.e7.bits.READ_OPTBUS; //нет подтверждения работоспособности оптического канала от другого БС для аварийного отключения

    modbus_table_can_out[209].bit.bit0 = edrk.errors.e5.bits.OP_PIT;
    modbus_table_can_out[209].bit.bit1 = edrk.errors.e5.bits.UTE4KA_WATER;
    modbus_table_can_out[209].bit.bit2 = edrk.errors.e1.bits.BLOCK_DOOR;
    modbus_table_can_out[209].bit.bit3 = edrk.errors.e7.bits.UMP_NOT_READY;
    modbus_table_can_out[209].bit.bit4 = edrk.errors.e5.bits.FAN;
    modbus_table_can_out[209].bit.bit5 = edrk.errors.e5.bits.PUMP_1;
    modbus_table_can_out[209].bit.bit6 = edrk.errors.e5.bits.PRE_READY_PUMP;
    modbus_table_can_out[209].bit.bit7 = edrk.errors.e5.bits.ERROR_HEAT;
    modbus_table_can_out[209].bit.bit8 = edrk.warnings.e5.bits.ERROR_ISOLATE;
    modbus_table_can_out[209].bit.bit9 = edrk.errors.e5.bits.ERROR_PRED_VIPR;
    modbus_table_can_out[209].bit.bit10 = edrk.errors.e5.bits.ERROR_ISOLATE;
    modbus_table_can_out[209].bit.bit11 = edrk.errors.e5.bits.POWER_UPC;
    modbus_table_can_out[209].bit.bit12 = edrk.errors.e5.bits.ERROR_GROUND_NET;
    modbus_table_can_out[209].bit.bit13 = edrk.errors.e5.bits.PUMP_2;
    modbus_table_can_out[209].bit.bit14 = edrk.from_ing1.bits.BLOCK_IZOL_NORMA ? 0 : 1;

    modbus_table_can_out[210].bit.bit0 = edrk.errors.e0.bits.U_1_MAX;
    modbus_table_can_out[210].bit.bit1 = edrk.errors.e0.bits.U_2_MAX;
    modbus_table_can_out[210].bit.bit2 = edrk.errors.e0.bits.U_1_MIN;
    modbus_table_can_out[210].bit.bit3 = edrk.errors.e0.bits.U_2_MIN;
    modbus_table_can_out[210].bit.bit4 = edrk.errors.e0.bits.U_A1B1_MAX;
    modbus_table_can_out[210].bit.bit5 = edrk.errors.e0.bits.U_A2B2_MAX;
    modbus_table_can_out[210].bit.bit6 = edrk.errors.e0.bits.U_B1C1_MAX;
    modbus_table_can_out[210].bit.bit7 = edrk.errors.e0.bits.U_B2C2_MAX;
    modbus_table_can_out[210].bit.bit8 = edrk.errors.e0.bits.U_A1B1_MIN;
    modbus_table_can_out[210].bit.bit9 = edrk.errors.e0.bits.U_A2B2_MIN;
    modbus_table_can_out[210].bit.bit10 = edrk.errors.e0.bits.U_B1C1_MIN;
    modbus_table_can_out[210].bit.bit11 = edrk.errors.e0.bits.U_B2C2_MIN;
    modbus_table_can_out[210].bit.bit12 = edrk.errors.e0.bits.U_IN_MAX;
    modbus_table_can_out[210].bit.bit13 = edrk.errors.e0.bits.U_IN_MIN;

    modbus_table_can_out[211].bit.bit0 = edrk.errors.e1.bits.I_UO2_MAX;
    modbus_table_can_out[211].bit.bit1 = edrk.errors.e1.bits.I_UO3_MAX;
    modbus_table_can_out[211].bit.bit2 = edrk.errors.e1.bits.I_UO4_MAX;
    modbus_table_can_out[211].bit.bit3 = edrk.errors.e1.bits.I_UO5_MAX;
    modbus_table_can_out[211].bit.bit4 = edrk.errors.e1.bits.I_UO6_MAX;
    modbus_table_can_out[211].bit.bit5 = edrk.errors.e1.bits.I_UO7_MAX;
    modbus_table_can_out[211].bit.bit6 = edrk.errors.e1.bits.I_BREAK_1_MAX;
    modbus_table_can_out[211].bit.bit7 = edrk.errors.e1.bits.I_BREAK_2_MAX;
    modbus_table_can_out[211].bit.bit8 = edrk.errors.e0.bits.I_1_MAX;
    modbus_table_can_out[211].bit.bit9 = edrk.errors.e0.bits.I_1_MAX;

    modbus_table_can_out[211].bit.bit10 = edrk.warnings.e2.bits.T_AIR0_MAX;
    modbus_table_can_out[211].bit.bit11 = edrk.warnings.e2.bits.T_AIR1_MAX;
    modbus_table_can_out[211].bit.bit12 = edrk.warnings.e2.bits.T_AIR2_MAX;
    modbus_table_can_out[211].bit.bit13 = edrk.warnings.e2.bits.T_AIR3_MAX;

    if (edrk.power_limit.all)
        modbus_table_can_out[211].bit.bit14 = 1;
    else
        modbus_table_can_out[211].bit.bit14 = 0;

    modbus_table_can_out[211].bit.bit15 = edrk.warnings.e10.bits.WARNING_I_OUT_OVER_1_6_NOMINAL;

    modbus_table_can_out[212].bit.bit0 = edrk.errors.e5.bits.ERROR_PRE_CHARGE_ON;
    modbus_table_can_out[212].bit.bit1 = edrk.errors.e7.bits.ERROR_SBOR_SHEMA;




    modbus_table_can_out[213].bit.bit0 = project.hwp[0].read.comp_s.plus.bit.ch0;
    modbus_table_can_out[213].bit.bit1 = project.hwp[0].read.comp_s.plus.bit.ch1;
    modbus_table_can_out[213].bit.bit2 = project.hwp[0].read.comp_s.plus.bit.ch2;
    modbus_table_can_out[213].bit.bit3 = project.hwp[0].read.comp_s.plus.bit.ch3;
    modbus_table_can_out[213].bit.bit4 = project.hwp[0].read.comp_s.plus.bit.ch4;
    modbus_table_can_out[213].bit.bit5 = project.hwp[0].read.comp_s.plus.bit.ch5;
    modbus_table_can_out[213].bit.bit6 = project.hwp[0].read.comp_s.plus.bit.ch6;
    modbus_table_can_out[213].bit.bit7 = project.hwp[0].read.comp_s.plus.bit.ch7;
    modbus_table_can_out[213].bit.bit8 = 0;
    modbus_table_can_out[213].bit.bit9 = project.hwp[0].read.comp_s.plus.bit.ch9;
    modbus_table_can_out[213].bit.bit10 = project.hwp[0].read.comp_s.plus.bit.ch10;
    modbus_table_can_out[213].bit.bit11 = project.hwp[0].read.comp_s.plus.bit.ch11;
    modbus_table_can_out[213].bit.bit12 = project.hwp[0].read.comp_s.plus.bit.ch12;
    modbus_table_can_out[213].bit.bit13 = project.hwp[0].read.comp_s.plus.bit.ch13;
    modbus_table_can_out[213].bit.bit14 = project.hwp[0].read.comp_s.plus.bit.ch14;
    modbus_table_can_out[213].bit.bit15 = project.hwp[0].read.comp_s.plus.bit.ch15;

    modbus_table_can_out[214].bit.bit0 = edrk.errors.e5.bits.LINE_ERR0;
    modbus_table_can_out[214].bit.bit1 = edrk.errors.e5.bits.LINE_HWP;
    modbus_table_can_out[214].bit.bit2 = project.hwp[0].read.comp_s.minus.bit.ch2;
    modbus_table_can_out[214].bit.bit3 = project.hwp[0].read.comp_s.minus.bit.ch3;
    modbus_table_can_out[214].bit.bit4 = project.hwp[0].read.comp_s.minus.bit.ch4;
    modbus_table_can_out[214].bit.bit5 = project.hwp[0].read.comp_s.minus.bit.ch5;
    modbus_table_can_out[214].bit.bit6 = project.hwp[0].read.comp_s.minus.bit.ch6;
    modbus_table_can_out[214].bit.bit7 = project.hwp[0].read.comp_s.minus.bit.ch7;
    modbus_table_can_out[214].bit.bit8 = 0;
    modbus_table_can_out[214].bit.bit9 = project.hwp[0].read.comp_s.minus.bit.ch9;
    modbus_table_can_out[214].bit.bit10 = project.hwp[0].read.comp_s.minus.bit.ch10;
    modbus_table_can_out[214].bit.bit11 = project.hwp[0].read.comp_s.minus.bit.ch11;
    modbus_table_can_out[214].bit.bit12 = project.hwp[0].read.comp_s.minus.bit.ch12;
    modbus_table_can_out[214].bit.bit13 = project.hwp[0].read.comp_s.minus.bit.ch13;
    modbus_table_can_out[214].bit.bit14 = project.hwp[0].read.comp_s.minus.bit.ch14;
    modbus_table_can_out[214].bit.bit15 = project.hwp[0].read.comp_s.minus.bit.ch15;

    modbus_table_can_out[215].bit.bit0 = edrk.errors.e8.bits.LOSS_INPUT_A1B1 | edrk.errors.e9.bits.DISBALANCE_Uin_1;    //TODO: вторая часть временная
    modbus_table_can_out[215].bit.bit1 = edrk.errors.e8.bits.LOSS_INPUT_B1C1 | edrk.errors.e9.bits.DISBALANCE_Uin_1;
    modbus_table_can_out[215].bit.bit2 = edrk.errors.e8.bits.LOSS_INPUT_A2B2 | edrk.errors.e9.bits.DISBALANCE_Uin_2;
    modbus_table_can_out[215].bit.bit3 = edrk.errors.e8.bits.LOSS_INPUT_B2C2 | edrk.errors.e9.bits.DISBALANCE_Uin_2;
    modbus_table_can_out[215].bit.bit4 = edrk.errors.e9.bits.U_IN_FREQ_NOT_NORMA;
    modbus_table_can_out[215].bit.bit5 = edrk.errors.e9.bits.U_IN_FREQ_NOT_STABLE;
    modbus_table_can_out[215].bit.bit6 = edrk.errors.e7.bits.READ_OPTBUS | edrk.errors.e7.bits.WRITE_OPTBUS;
    modbus_table_can_out[215].bit.bit7 = edrk.errors.e7.bits.MASTER_SLAVE_SYNC;
    modbus_table_can_out[215].bit.bit8 = project.controller.read.errors_buses.bit.err_sbus;
    modbus_table_can_out[215].bit.bit9 = project.controller.read.errors.bit.error_pbus || project.controller.read.errors_buses.bit.slave_addr_error
            || project.controller.read.errors_buses.bit.count_error_pbus;
    modbus_table_can_out[215].bit.bit10 = edrk.errors.e6.bits.ER_DISBAL_BATT;
    modbus_table_can_out[215].bit.bit11 = edrk.errors.e6.bits.QTV_ERROR_NOT_U;
    modbus_table_can_out[215].bit.bit12 = edrk.errors.e6.bits.ERROR_PRE_CHARGE_U;
    modbus_table_can_out[215].bit.bit13 = edrk.errors.e8.bits.U_IN_20_PROCENTS_HIGH;
    modbus_table_can_out[215].bit.bit14 = edrk.errors.e8.bits.U_IN_10_PROCENTS_LOW;
    modbus_table_can_out[215].bit.bit15 = edrk.errors.e8.bits.U_IN_20_PROCENTS_LOW;

    modbus_table_can_out[216].bit.bit0 = project.cds_tk[0].read.sbus.lock_status_error.bit.err_power;
    modbus_table_can_out[216].bit.bit1 = project.cds_tk[1].read.sbus.lock_status_error.bit.err_power;
    modbus_table_can_out[216].bit.bit2 = project.cds_tk[2].read.sbus.lock_status_error.bit.err_power;
    modbus_table_can_out[216].bit.bit3 = project.cds_tk[3].read.sbus.lock_status_error.bit.err_power;
    modbus_table_can_out[216].bit.bit4 = project.cds_in[0].read.sbus.lock_status_error.bit.err_power;
    modbus_table_can_out[216].bit.bit5 = project.cds_in[1].read.sbus.lock_status_error.bit.err_power;
    modbus_table_can_out[216].bit.bit6 = project.cds_out[0].read.sbus.lock_status_error.bit.err_power;
    modbus_table_can_out[216].bit.bit7 = edrk.errors.e7.bits.NOT_VALID_CONTROL_STATION;
    modbus_table_can_out[216].bit.bit8 = edrk.errors.e8.bits.LOSS_OUTPUT_U1;
    modbus_table_can_out[216].bit.bit9 = edrk.errors.e8.bits.LOSS_OUTPUT_V1;
    modbus_table_can_out[216].bit.bit10 = edrk.errors.e8.bits.LOSS_OUTPUT_W1;
    modbus_table_can_out[216].bit.bit11 = edrk.errors.e8.bits.LOSS_OUTPUT_U2;
    modbus_table_can_out[216].bit.bit12 = edrk.errors.e8.bits.LOSS_OUTPUT_V2;
    modbus_table_can_out[216].bit.bit13 = edrk.errors.e8.bits.LOSS_OUTPUT_W2;
    modbus_table_can_out[216].bit.bit14 = edrk.errors.e8.bits.DISBALANCE_IM1_IM2;
    modbus_table_can_out[216].bit.bit15 = edrk.errors.e7.bits.VERY_FAST_GO_0to1;

    modbus_table_can_out[217].bit.bit0 = project.cds_tk[0].read.sbus.lock_status_error.bit.err_switch;
    modbus_table_can_out[217].bit.bit1 = project.cds_tk[1].read.sbus.lock_status_error.bit.err_switch;
    modbus_table_can_out[217].bit.bit2 = project.cds_tk[2].read.sbus.lock_status_error.bit.err_switch;
    modbus_table_can_out[217].bit.bit3 = project.cds_tk[3].read.sbus.lock_status_error.bit.err_switch;
    modbus_table_can_out[217].bit.bit4 = project.cds_in[0].read.sbus.lock_status_error.bit.err_switch;
    modbus_table_can_out[217].bit.bit5 = project.cds_in[1].read.sbus.lock_status_error.bit.err_switch;
    modbus_table_can_out[217].bit.bit6 = project.cds_out[0].read.sbus.lock_status_error.bit.err_switch;
    modbus_table_can_out[217].bit.bit7 = project.adc[0].read.sbus.lock_status_error.bit.err_switch;
    modbus_table_can_out[217].bit.bit8 = 0;
    modbus_table_can_out[217].bit.bit9 = project.adc[1].read.sbus.lock_status_error.bit.err_switch;

    modbus_table_can_out[218].bit.bit0 = edrk.warnings.e2.bits.T_UO1_MAX;
    modbus_table_can_out[218].bit.bit1 = edrk.warnings.e2.bits.T_UO2_MAX;
    modbus_table_can_out[218].bit.bit2 = edrk.warnings.e2.bits.T_UO3_MAX;
    modbus_table_can_out[218].bit.bit3 = edrk.warnings.e2.bits.T_UO4_MAX;
    modbus_table_can_out[218].bit.bit4 = edrk.warnings.e2.bits.T_UO5_MAX;
    modbus_table_can_out[218].bit.bit5 = edrk.warnings.e2.bits.T_UO6_MAX;
    modbus_table_can_out[218].bit.bit6 = edrk.warnings.e2.bits.T_UO7_MAX;
    modbus_table_can_out[218].bit.bit7 = edrk.errors.e2.bits.T_UO1_MAX;
    modbus_table_can_out[218].bit.bit8 = edrk.errors.e2.bits.T_UO2_MAX;
    modbus_table_can_out[218].bit.bit9 = edrk.errors.e2.bits.T_UO3_MAX;
    modbus_table_can_out[218].bit.bit10 = edrk.errors.e2.bits.T_UO4_MAX;
    modbus_table_can_out[218].bit.bit11 = edrk.errors.e2.bits.T_UO5_MAX;
    modbus_table_can_out[218].bit.bit12 = edrk.errors.e2.bits.T_UO6_MAX;
    modbus_table_can_out[218].bit.bit13 = edrk.errors.e2.bits.T_UO7_MAX;

    modbus_table_can_out[219].bit.bit0 = edrk.warnings.e7.bits.READ_OPTBUS | edrk.warnings.e7.bits.WRITE_OPTBUS;
    modbus_table_can_out[219].bit.bit1 = edrk.warnings.e7.bits.MASTER_SLAVE_SYNC;
    modbus_table_can_out[219].bit.bit2 = edrk.errors.e6.bits.ERROR_PRE_CHARGE_ANSWER;
    modbus_table_can_out[219].bit.bit3 = edrk.warnings.e1.bits.NO_INPUT_SYNC_SIGNAL;
    modbus_table_can_out[219].bit.bit4 = edrk.errors.e1.bits.NO_INPUT_SYNC_SIGNAL;
    modbus_table_can_out[219].bit.bit5 = edrk.errors.e3.bits.ERR_INT_PWM_LONG
            || edrk.errors.e9.bits.ERR_PWM_WDOG
            || edrk.errors.e9.bits.ERR_INT_PWM_VERY_LONG;
    modbus_table_can_out[219].bit.bit15 = edrk.errors.e5.bits.T_VIPR_MAX;

    modbus_table_can_out[220].bit.bit0 = edrk.errors.e2.bits.T_AIR0_MAX;
    modbus_table_can_out[220].bit.bit1 = edrk.errors.e2.bits.T_AIR1_MAX;
    modbus_table_can_out[220].bit.bit2 = edrk.errors.e2.bits.T_AIR2_MAX;
    modbus_table_can_out[220].bit.bit3 = edrk.errors.e2.bits.T_AIR3_MAX;
    modbus_table_can_out[220].bit.bit4 = edrk.warnings.e10.bits.T_BSU_Sensor_BK1;
    modbus_table_can_out[220].bit.bit5 = edrk.errors.e10.bits.T_BSU_Sensor_BK1;
    modbus_table_can_out[220].bit.bit6 = edrk.warnings.e10.bits.T_BSU_Sensor_BK2;
    modbus_table_can_out[220].bit.bit7 = edrk.errors.e10.bits.T_BSU_Sensor_BK2;

    modbus_table_can_out[220].bit.bit8 = edrk.errors.e2.bits.T_WATER_EXT_MAX;
    modbus_table_can_out[220].bit.bit9 = edrk.errors.e2.bits.T_WATER_INT_MAX;
    modbus_table_can_out[220].bit.bit10 = edrk.warnings.e2.bits.T_WATER_EXT_MAX;
    modbus_table_can_out[220].bit.bit11 = edrk.warnings.e2.bits.T_WATER_INT_MAX;

    modbus_table_can_out[220].bit.bit12 = edrk.errors.e7.bits.T_ACDRIVE_BEAR_MAX_DNE;
    modbus_table_can_out[220].bit.bit13 = edrk.errors.e9.bits.T_ACDRIVE_BEAR_MAX_NE;
    modbus_table_can_out[220].bit.bit14 = edrk.warnings.e7.bits.T_ACDRIVE_BEAR_MAX_DNE;
    modbus_table_can_out[220].bit.bit15 = edrk.warnings.e9.bits.T_ACDRIVE_BEAR_MAX_NE;

    modbus_table_can_out[221].bit.bit0 = edrk.errors.e10.bits.T_ACDRIVE_WINDING_U1;
    modbus_table_can_out[221].bit.bit1 = edrk.errors.e10.bits.T_ACDRIVE_WINDING_V1;
    modbus_table_can_out[221].bit.bit2 = edrk.errors.e10.bits.T_ACDRIVE_WINDING_W1;
    modbus_table_can_out[221].bit.bit3 = edrk.errors.e10.bits.T_ACDRIVE_WINDING_U2;
    modbus_table_can_out[221].bit.bit4 = edrk.errors.e10.bits.T_ACDRIVE_WINDING_V2;
    modbus_table_can_out[221].bit.bit5 = edrk.errors.e10.bits.T_ACDRIVE_WINDING_W2;
    modbus_table_can_out[221].bit.bit6 = edrk.warnings.e10.bits.T_ACDRIVE_WINDING_U1;
    modbus_table_can_out[221].bit.bit7 = edrk.warnings.e10.bits.T_ACDRIVE_WINDING_V1;
    modbus_table_can_out[221].bit.bit8 = edrk.warnings.e10.bits.T_ACDRIVE_WINDING_W1;
    modbus_table_can_out[221].bit.bit9 = edrk.warnings.e10.bits.T_ACDRIVE_WINDING_U2;
    modbus_table_can_out[221].bit.bit10 = edrk.warnings.e10.bits.T_ACDRIVE_WINDING_V2;
    modbus_table_can_out[221].bit.bit11 = edrk.warnings.e10.bits.T_ACDRIVE_WINDING_W2;

    modbus_table_can_out[222].bit.bit0 = edrk.errors.e2.bits.P_WATER_INT_MAX;
    modbus_table_can_out[222].bit.bit1 = edrk.errors.e2.bits.P_WATER_INT_MIN;
    modbus_table_can_out[222].bit.bit2 = edrk.warnings.e2.bits.P_WATER_INT_MAX;
    modbus_table_can_out[222].bit.bit3 = edrk.warnings.e2.bits.P_WATER_INT_MIN;


    modbus_table_can_out[223].all = edrk.errors.e11.all;



}

void update_protect_levels_to_MPU() {
    modbus_table_can_out[139].all = protect_levels.abnormal_temper_acdrive_winding_U1 / 10;
    modbus_table_can_out[140].all = protect_levels.abnormal_temper_acdrive_winding_V1 / 10;
    modbus_table_can_out[141].all = protect_levels.abnormal_temper_acdrive_winding_W1 / 10;
    modbus_table_can_out[142].all = protect_levels.abnormal_temper_acdrive_winding_U2 / 10;
    modbus_table_can_out[143].all = protect_levels.abnormal_temper_acdrive_winding_V2 / 10;
    modbus_table_can_out[144].all = protect_levels.abnormal_temper_acdrive_winding_W2 / 10;
    modbus_table_can_out[145].all = protect_levels.abnormal_temper_acdrive_bear_DNE / 10;
    modbus_table_can_out[146].all = protect_levels.abnormal_temper_acdrive_bear_NE / 10;

    modbus_table_can_out[147].all = protect_levels.alarm_temper_acdrive_winding_U1 / 10;
    modbus_table_can_out[148].all = protect_levels.alarm_temper_acdrive_winding_V1 / 10;
    modbus_table_can_out[149].all = protect_levels.alarm_temper_acdrive_winding_W1 / 10;
    modbus_table_can_out[150].all = protect_levels.alarm_temper_acdrive_winding_U2 / 10;
    modbus_table_can_out[151].all = protect_levels.alarm_temper_acdrive_winding_V2 / 10;
    modbus_table_can_out[152].all = protect_levels.alarm_temper_acdrive_winding_W2 / 10;
    modbus_table_can_out[153].all = protect_levels.alarm_temper_acdrive_bear_DNE / 10;
    modbus_table_can_out[154].all = protect_levels.alarm_temper_acdrive_bear_NE / 10;

    modbus_table_can_out[155].all = protect_levels.abnormal_temper_u_01 / 10;
    modbus_table_can_out[156].all = protect_levels.abnormal_temper_u_02 / 10;
    modbus_table_can_out[157].all = protect_levels.abnormal_temper_u_03 / 10;
    modbus_table_can_out[158].all = protect_levels.abnormal_temper_u_04 / 10;
    modbus_table_can_out[159].all = protect_levels.abnormal_temper_u_05 / 10;
    modbus_table_can_out[160].all = protect_levels.abnormal_temper_u_06 / 10;
    modbus_table_can_out[161].all = protect_levels.abnormal_temper_u_07 / 10;
    modbus_table_can_out[162].all = protect_levels.alarm_temper_u_01 / 10;
    modbus_table_can_out[163].all = protect_levels.alarm_temper_u_02 / 10;
    modbus_table_can_out[164].all = protect_levels.alarm_temper_u_03 / 10;
    modbus_table_can_out[165].all = protect_levels.alarm_temper_u_04 / 10;
    modbus_table_can_out[166].all = protect_levels.alarm_temper_u_05 / 10;
    modbus_table_can_out[167].all = protect_levels.alarm_temper_u_06 / 10;
    modbus_table_can_out[168].all = protect_levels.alarm_temper_u_07 / 10;

    modbus_table_can_out[169].all = protect_levels.abnormal_temper_water_ext / 10;
    modbus_table_can_out[170].all = protect_levels.abnormal_temper_water_int / 10;
    modbus_table_can_out[171].all = protect_levels.alarm_p_water_min_int / 100;
    modbus_table_can_out[172].all = protect_levels.alarm_temper_water_int / 10;
    modbus_table_can_out[173].all = protect_levels.alarm_temper_water_ext / 10;
    modbus_table_can_out[174].all = protect_levels.alarm_p_water_max_int / 100;

    modbus_table_can_out[175].all = protect_levels.abnormal_temper_air_int_01 / 10;
    modbus_table_can_out[176].all = protect_levels.abnormal_temper_air_int_02 / 10;
    modbus_table_can_out[177].all = protect_levels.abnormal_temper_air_int_03 / 10;
    modbus_table_can_out[178].all = protect_levels.abnormal_temper_air_int_04 / 10;
    modbus_table_can_out[179].all = protect_levels.alarm_temper_air_int_01 / 10;
    modbus_table_can_out[180].all = protect_levels.alarm_temper_air_int_02 / 10;
    modbus_table_can_out[181].all = protect_levels.alarm_temper_air_int_03 / 10;
    modbus_table_can_out[182].all = protect_levels.alarm_temper_air_int_04 / 10;

    modbus_table_can_out[183].all = _IQtoF(analog_protect.in_voltage[0].setup.levels.iqNominal_minus20) * NORMA_ACP;//_IQtoF(edrk.iqMIN_U_IN) * NORMA_ACP;
    modbus_table_can_out[184].all = _IQtoF(analog_protect.in_voltage[1].setup.levels.iqNominal_minus20) * NORMA_ACP;
    modbus_table_can_out[185].all = _IQtoF(analog_protect.in_voltage[0].setup.levels.iqNominal_plus20) * NORMA_ACP;//_IQtoF(edrk.iqMIN_U_ZPT) * NORMA_ACP;
    modbus_table_can_out[186].all = _IQtoF(analog_protect.in_voltage[1].setup.levels.iqNominal_plus20) * NORMA_ACP;
    modbus_table_can_out[187].all = //_IQtoF(edrk.iqMAX_U_IN) * NORMA_ACP;
    modbus_table_can_out[188].all = _IQtoF(edrk.iqMAX_U_IN) * NORMA_ACP;
    modbus_table_can_out[189].all = //_IQtoF(edrk.iqMAX_U_ZPT) * NORMA_ACP;
    modbus_table_can_out[190].all = _IQtoF(edrk.iqMAX_U_ZPT) * NORMA_ACP;

    modbus_table_can_out[191].all = protect_levels.alarm_Izpt_max;

    modbus_table_can_out[192].all = protect_levels.alarm_Imax_U01;
    modbus_table_can_out[193].all = protect_levels.alarm_Imax_U02;
    modbus_table_can_out[194].all = protect_levels.alarm_Imax_U03;
    modbus_table_can_out[195].all = protect_levels.alarm_Imax_U04;
    modbus_table_can_out[196].all = protect_levels.alarm_Imax_U05;
    modbus_table_can_out[197].all = protect_levels.alarm_Imax_U06;
    modbus_table_can_out[198].all = protect_levels.alarm_Imax_U07;
    modbus_table_can_out[199].all = protect_levels.alarm_Iged_max;
}
