matlab_23550/Inu/Src/main/sbor_shema.c
2024-12-27 10:50:32 +03:00

1765 lines
53 KiB
C

/*
* sbor_shema.c
*
* Created on: 18 ôåâð. 2021 ã.
* Author: stud
*/
#include "sbor_shema.h"
#include "IQmathLib.h"
#include "edrk_main.h"
#include "optical_bus.h"
#include "adc_tools.h"
#include "control_station.h"
#include "control_station_project.h"
#include "digital_filters.h"
#include "detect_errors.h"
#define RASCEPITEL_MANUAL_ALWAYS_ON 0//1
///////////////////////////////////////////////
///////////////////////////////////////////////
//#define IQ_MINIMAL_DELTA_RUN_CHARGE_1 559240 //100V
//#define IQ_MINIMAL_DELTA_RUN_CHARGE_2 1118480 //200V
//#define IQ_MINIMAL_DELTA_RUN_CHARGE 279620 // 50V
#define IQ_MINIMAL_DELTA_RUN_CHARGE_1 1118480// 200 V ///279620 // 50V
#define IQ_MINIMAL_DELTA_RUN_CHARGE_2 1118480// 200 V //279620 // 50V
#define IQ_MINIMAL_DELTA_RUN_WORK 2796202 // 500V // 2236960 // 400V // 1677720 // 300 V // 559240 // 100V
#define IQ_MINIMAL_ZAD_U_CHARGE 55924 // 10V
#define IQ_MAXIMAL_ZAD_U_CHARGE 14596177 // 2610V
#define IQ_MINIMAL_DELTA_RUN_CHARGE2 139810 //25 V
#define TIME_WAIT_CHARGE_ON 300 //30 sec
#define TIME_PAUSE_U_RISE 30 // 1 sec
#define IQ_MINIMAL_RISE_U 55924 // 10V
unsigned int zaryad_on_off(unsigned int flag)
{
static int restart_charge=0, batt_ok = 0;
static unsigned int time_wait_on_charge=0;
static unsigned int time_pause_detect_u_rise=0;
static _iq prev_U1=0, prev_U2 = 0;
batt_ok = 0;
// ðàçáåæêà ïî áàíêàì - îøèáêà!!!
if (_IQabs(filter.iqU_1_long-filter.iqU_2_long)>IQ_MINIMAL_DELTA_RUN_WORK)
{
// edrk.errors.e6.bits.ERROR_PRE_CHARGE_U |= 1;
edrk.errors.e6.bits.ER_DISBAL_BATT |= 1;
edrk.to_ing.bits.ZARYAD_ON = 0;
batt_ok = 0;
}
if (flag && edrk.summ_errors==0 && edrk.errors.e6.bits.ERROR_PRE_CHARGE_U==0 && edrk.errors.e6.bits.ER_DISBAL_BATT==0 )
{
// íåò çàäàíèß!!!
if ((edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_ZAD_U_CHARGE) <= 0)
{
edrk.errors.e5.bits.ERROR_PRE_CHARGE_ON |= 1;
edrk.to_ing.bits.ZARYAD_ON = 0;
return 0;
}
// áîëüøîå çàäàíèå!!!
if ((IQ_MAXIMAL_ZAD_U_CHARGE - edrk.zadanie.iq_ZadanieU_Charge) < 0)
{
edrk.errors.e5.bits.ERROR_PRE_CHARGE_ON |= 1;
edrk.to_ing.bits.ZARYAD_ON = 0;
return 0;
}
// åñòü ðàçáåæêà ïî áàíêàì
if (_IQabs(filter.iqU_1_long-filter.iqU_2_long)>IQ_MINIMAL_DELTA_RUN_WORK) //IQ_MINIMAL_DELTA_RUN_CHARGE_1
{
edrk.errors.e6.bits.ER_DISBAL_BATT |= 1;
edrk.to_ing.bits.ZARYAD_ON = 0;
return 0;
}
if (restart_charge == 0)
{
// çàðßä íîðìà è áûëî âêëþ÷åíî, âûêëþ÷àåì
if ( edrk.from_ing1.bits.ZARYAD_ON &&
(filter.iqU_1_long>=(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE_1)
|| filter.iqU_2_long>=(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE_1))
)
{
restart_charge = 1;
edrk.to_ing.bits.ZARYAD_ON = 0;
}
else
{
//TODO !!! ïî ñóòè ïîâòîðÿåò ïðåäûäóùèé if. Óäàëèòü?
if ( edrk.from_ing1.bits.ZARYAD_ON==0 &&
(filter.iqU_1_long>=(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE_2)
|| filter.iqU_2_long>=(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE_2)) )
{
restart_charge = 1;
edrk.to_ing.bits.ZARYAD_ON = 0;
}
else
{
// çàðßä ìåíüøå íóæíîãî, âêëþ÷àåì.
if ( (filter.iqU_1_long<(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE_2))
&& (filter.iqU_2_long<(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE_2)) )
edrk.to_ing.bits.ZARYAD_ON = 1;
}
}
if (pause_detect_error(&time_pause_detect_u_rise,TIME_PAUSE_U_RISE,1))
{
time_pause_detect_u_rise = 0;
if (((filter.iqU_1_long-prev_U1)>=IQ_MINIMAL_RISE_U) ||
((filter.iqU_2_long-prev_U2)>=IQ_MINIMAL_RISE_U) )
time_wait_on_charge = 0;
prev_U1 = filter.iqU_1_long;
prev_U2 = filter.iqU_2_long;
}
// íå äîæäàëèñü çàðßäà!!!
if (pause_detect_error(&time_wait_on_charge,TIME_WAIT_CHARGE_ON,1))
edrk.errors.e6.bits.ERROR_PRE_CHARGE_U |= 1;
/*
if (filter.iqU_1_long>=(edrk.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE2)
|| filter.iqU_2_long>=(edrk.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE2))
{
restart_charge = 1;
edrk.to_ing.bits.ZARYAD_ON = 0;
}
else
{
// åñòü ðàçáåæêà ïî áàíêàì
if (_IQabs(filter.iqU_1_long-filter.iqU_2_long)>IQ_MINIMAL_DELTA_RUN_CHARGE)
edrk.errors.e6.bits.ER_DISBAL_BATT |= 1;
// çàðßä ìåíüøå íóæíîãî, âêëþ÷àåì.
if ( (filter.iqU_1_long<(edrk.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE))
|| (filter.iqU_2_long<(edrk.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE)) )
edrk.to_ing.bits.ZARYAD_ON = 1;
if ( (filter.iqU_1_long>=(edrk.iq_ZadanieU_Charge))
&& (filter.iqU_2_long>=(edrk.iq_ZadanieU_Charge)) )
{
restart_charge = 1;
edrk.to_ing.bits.ZARYAD_ON = 0;
}
}
*/
}
else//restart_charge==0
{
// ïî÷åìó-òî çàðßä ñòàë ìåíüøå!!!
if ( (filter.iqU_1_long<(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE_2))
|| (filter.iqU_2_long<(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE_2)) )
edrk.errors.e6.bits.ERROR_PRE_CHARGE_U |= 1;
} //restart_charge==0
}
else // flag==1
{
restart_charge = 0;
edrk.to_ing.bits.ZARYAD_ON = 0;
time_wait_on_charge = 0;
prev_U1 = filter.iqU_1_long;
prev_U2 = filter.iqU_2_long;
}
if ( (filter.iqU_1_long>=(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE_2))
&& (filter.iqU_2_long>=(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE_2))
&& (_IQabs(filter.iqU_1_long-filter.iqU_2_long)<IQ_MINIMAL_DELTA_RUN_WORK)
&& (filter.iqU_1_long<=(edrk.zadanie.iq_ZadanieU_Charge+IQ_MINIMAL_DELTA_RUN_CHARGE_2))
&& (filter.iqU_2_long<=(edrk.zadanie.iq_ZadanieU_Charge+IQ_MINIMAL_DELTA_RUN_CHARGE_2))
&& edrk.to_ing.bits.ZARYAD_ON==0
&& edrk.from_ing1.bits.ZARYAD_ON==0
&& edrk.errors.e5.bits.ERROR_PRE_CHARGE_ON==0
&& edrk.errors.e6.bits.ERROR_PRE_CHARGE_U==0
)
batt_ok = 1;
// return (restart_charge && edrk.errors.e5.bits.ERROR_PRE_CHARGE_ON==0 && edrk.errors.e6.bits.ERROR_PRE_CHARGE_U==0);
return batt_ok;
}
///////////////////////////////////////////////
///////////////////////////////////////////////
void set_status_pump_fan(void)
{
if (edrk.from_ing1.bits.VENTIL_ON==1)
edrk.StatusFunAll = 1;
else
edrk.StatusFunAll = 0;
/*
if ((edrk.from_ing.bits.NASOS_NORMA == 1) &&
edrk.StartPump && edrk.errors.e5.bits.PRE_READY_PUMP == 0 &&
(edrk.to_ing.bits.NASOS_1_ON || edrk.to_ing.bits.NASOS_2_ON) &&
(edrk.errors.e5.bits.PUMP_1==0) && (edrk.errors.e5.bits.PUMP_2==0) &&
edrk.errors.e2.bits.P_WATER_INT_MAX==0 && edrk.errors.e2.bits.P_WATER_INT_MIN==0)
*/
if (
(edrk.from_ing1.bits.NASOS_NORMA == 1) &&
(edrk.to_ing.bits.NASOS_1_ON || edrk.to_ing.bits.NASOS_2_ON) &&
edrk.from_ing1.bits.NASOS_ON && edrk.errors.e5.bits.PRE_READY_PUMP == 0 &&
(edrk.errors.e5.bits.PUMP_1==0) && (edrk.errors.e5.bits.PUMP_2==0)
)
{
if (edrk.to_ing.bits.NASOS_1_ON)
edrk.StatusPump0 = 1;
else
edrk.StatusPump0 = 0;
if (edrk.to_ing.bits.NASOS_2_ON)
edrk.StatusPump1 = 1;
else
edrk.StatusPump1 = 0;
edrk.StatusPumpAll = 1;
}
else
{
edrk.StatusPump0 = 0;
edrk.StatusPump1 = 0;
edrk.StatusPumpAll = 0;
}
if (edrk.StatusFunAll && edrk.StatusPumpAll)
edrk.StatusPumpFanAll = 1;
else
{
// åñëè åñòü çàïðåò ïóñêà íàñîñîâ èç òåðìèíàëêè, òî èìèòèðóåì âêëþ÷åíÿè íàñîñîâ è âåíòèëÿòîðîâ.
if (control_station.active_array_cmd[CONTROL_STATION_CMD_DISABLE_ON_PUMP])
edrk.StatusPumpFanAll = 1;
else
{
edrk.StatusPumpFanAll = 0;
}
}
}
///////////////////////////////////////////////
///////////////////////////////////////////////
int detect_zaryad_ump(void)
{
if (edrk.from_shema_filter.bits.UMP_ON_OFF==1)
{
if ( (filter.iqUin_m1>=edrk.iqMIN_U_IN)
&& (filter.iqUin_m2>=edrk.iqMIN_U_IN)
&& (filter.iqUin_m1<=edrk.iqMAX_U_IN)
&& (filter.iqUin_m2<=edrk.iqMAX_U_IN) )
return 1;
else
return 0;
}
else
return 0;
}
///////////////////////////////////////////////
///////////////////////////////////////////////
///////////////////////////////////////////////
///////////////////////////////////////////////
///////////////////////////////////////////////
///////////////////////////////////////////////
///////////////////////////////////////////////
///////////////////////////////////////////////
///////////////////////////////////////////////
#define TIME_WAIT_SBOR 8500
#define TIME_WAIT_ANSWER_NASOS 500
#define TIME_WAIT_OK_NASOS 50
///////////////////////////////////////////////
///////////////////////////////////////////////
void sbor_shema_pusk_nasos(unsigned int t_start, unsigned int t_finish)
{
static unsigned int time_error_nasos = 0;
static unsigned int time_ok_nasos = 0;
int status_pump, status_pump_long;
// ïóñê íàñîñà
if (edrk.Sbor_Mode == t_start)
{
edrk.enter_to_pump_stage = 1;
// ñáðîñèëè ïðåäóïðåæäåíèÿ ïî íàñîñàì, âîçìîæíî è íå ïðàâèëüíî ýòî!
edrk.warnings.e5.bits.PUMP_1 = edrk.warnings.e5.bits.PUMP_2 = 0;
if (control_station.active_array_cmd[CONTROL_STATION_CMD_DISABLE_ON_PUMP]==0)
edrk.AutoStartPump = 1;
time_error_nasos = 0;
time_ok_nasos = 0;
if (control_station.active_array_cmd[CONTROL_STATION_CMD_DISABLE_ON_PUMP]==1)
edrk.Sbor_Mode = t_finish; // èìèòàöèÿ çàâåðøåíèÿ ïóñêà íàñîñà
}
// æäåì ïóñêà íàñîñà
if (edrk.Sbor_Mode>t_start && edrk.Sbor_Mode<t_finish)
{
edrk.Stage_Sbor = STAGE_SBOR_STATUS_PUMP;
status_pump = get_status_p_water_min(edrk.StatusPumpFanAll);
/* if (status & 4)
edrk.errors.e2.bits.P_WATER_INT_MIN |= 1;
if (status==2)
edrk.warnings.e2.bits.P_WATER_INT_MIN = 1;
if (status==1)
edrk.warnings.e2.bits.P_WATER_INT_MIN = 0;
*/
// æäåì íåêîòîðîå âðåìÿ ïîêà êà÷àåò íàñîñ ñ íîðìàëüíûì äàâëåíèåì status_pump == 1
if (status_pump)
{
if (pause_detect_error(&time_ok_nasos,TIME_WAIT_OK_NASOS,1))
{
status_pump_long = 1;
}
}
else
{
time_ok_nasos = 0;
status_pump_long = 0;
}
if (edrk.StatusPumpFanAll && status_pump==1) // æäåì ïóñêà íàñîñà è äàâëåíèÿ
{
edrk.Sbor_Mode = t_finish;
}
// íàñîñ íå ïóñòèëñÿ, ïðîáóåì âòîðîé
if (edrk.Sbor_Mode==(t_start + ((t_finish-t_start)>>1) ))
{
}
// íàñîñ íå ïóñòèëñÿ, îøèáêà
if (edrk.Sbor_Mode==(t_finish-1))
{
edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1;
edrk.errors.e11.bits.ERROR_PUMP_ON_SBOR |= 1;
edrk.Status_Sbor = 2;
edrk.AutoStartPump = 0;
}
}
// àíàëèç óæå ïîñëå çàïóñêà íàñîñà
if (edrk.Sbor_Mode>t_finish)
{
if (edrk.StatusPumpFanAll==0)
{
// íàñîñ âûêëþ÷èëñÿ âäðóã
if (edrk.SelectPump1_2==1)
{
// ìû áûëè â àâòîâûáîðå íàñîñà 1
// æäåì íåêîòîðîå âðåìÿ ïîêà ïåðåêëþ÷àåòñÿ íàñîñ
if (pause_detect_error(&time_error_nasos,TIME_WAIT_ANSWER_NASOS,1))
{
edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1;
edrk.errors.e11.bits.ERROR_RESTART_PUMP_1_ON_SBOR |= 1;
edrk.Status_Sbor = 102;
edrk.AutoStartPump = 0;
}
}
else
if (edrk.SelectPump1_2==2)
{
// ìû áûëè â àâòîâûáîðå íàñîñà 2
// æäåì íåêîòîðîå âðåìÿ ïîêà ïåðåêëþ÷àåòñÿ íàñîñ
if (pause_detect_error(&time_error_nasos,TIME_WAIT_ANSWER_NASOS,1))
{
edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1;
edrk.errors.e11.bits.ERROR_RESTART_PUMP_1_ON_SBOR |= 1;
edrk.Status_Sbor = 102;
edrk.AutoStartPump = 0;
}
}
else
{
edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1;
edrk.errors.e11.bits.ERROR_RESTART_PUMP_ALL_ON_SBOR |= 1;
edrk.Status_Sbor = 102;
edrk.AutoStartPump = 0;
}
}
else
time_error_nasos = 0;
}
}
void sbor_shema_pusk_zaryad(unsigned int t_start, unsigned int t_finish)
{
/////////////////////////////////////
// çàïóñê çàðÿäà âíóòðåííåãî
if (edrk.Sbor_Mode == t_start)
{
if (control_station.active_array_cmd[CONTROL_STATION_CMD_ENABLE_ON_CHARGE]==1)
edrk.Run_Pred_Zaryad = 1; // çàïóñê ïðåäçàðßäà!
}
// æäåì çàâåðøåíèÿ ðàáîòû ïðåäçàðÿäà
// òóò ïðåäçàðßä äîëæåí óæå çàêîí÷èòü ðàáîòó
if (edrk.Sbor_Mode>t_start && edrk.Sbor_Mode<t_finish && (edrk.Status_Charge || (control_station.active_array_cmd[CONTROL_STATION_CMD_ENABLE_ON_CHARGE]==0))
&& edrk.from_ing1.bits.ZARYAD_ON==0 && edrk.StatusPumpFanAll)
{
edrk.Stage_Sbor = STAGE_SBOR_STATUS_ZARYAD;
if ((edrk.Status_Charge || (control_station.active_array_cmd[CONTROL_STATION_CMD_ENABLE_ON_CHARGE]==0))
&& edrk.from_ing1.bits.ZARYAD_ON==0 && edrk.StatusPumpFanAll)
{
edrk.Zaryad_OK = 1;
edrk.Run_Pred_Zaryad = 0;
edrk.Sbor_Mode = t_finish;
}
// íåò çàðÿäà, îøèáêà
if (edrk.Sbor_Mode==(t_finish-1))
{
edrk.Run_Pred_Zaryad = 0;
edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1;
edrk.errors.e11.bits.ERROR_PRED_ZARYAD |= 1;
edrk.Status_Sbor = 4;
}
}
if (edrk.Sbor_Mode>t_finish)
{
if (edrk.Zaryad_OK==0 || edrk.from_ing1.bits.ZARYAD_ON==1 )
{
edrk.Run_Pred_Zaryad = 0;
edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1;
edrk.errors.e11.bits.ERROR_PRED_ZARYAD_AFTER |= 1;
edrk.Status_Sbor = 104;
}
}
}
void sbor_shema_pusk_ump(unsigned int t_start, unsigned int t_finish)
{
static int enable_run_ump=0;
// âêëþ÷àåì UMP
if (edrk.Sbor_Mode==t_start && edrk.Zaryad_OK == 1)
{
// edrk.Run_UMP = 1;
enable_run_ump = 0;
}
if (edrk.Sbor_Mode>t_start && edrk.Sbor_Mode<t_finish)
{
if (enable_run_ump==0)
{
if (edrk.from_shema_filter.bits.READY_UMP==1
|| control_station.active_array_cmd[CONTROL_STATION_CMD_DISABLE_ON_UMP]==1)
{
edrk.Run_UMP = 1;
enable_run_ump = 1;
}
}
edrk.Stage_Sbor = STAGE_SBOR_STATUS_UMP_ON;
if (edrk.Zaryad_OK == 1 && edrk.Status_UMP_Ok==1 && edrk.Zaryad_UMP_Ok==1)
edrk.Sbor_Mode = t_finish;
// íåò çàðÿäà, îøèáêà
if (edrk.Sbor_Mode==(t_finish-1))
{
edrk.Run_UMP = 0;
edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1;
edrk.errors.e11.bits.ERROR_UMP_NOT_ON |= 1;
edrk.Status_Sbor = 5;
}
}
// if (edrk.Sbor_Mode>t_finish && (edrk.Zaryad_OK == 0 || edrk.Status_UMP_Ok==0))
// {
//
// edrk.Run_UMP = 0;
// edrk.Run_Pred_Zaryad = 0;
// edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1;
// edrk.errors.e7.bits.UMP_NOT_ANSWER |= 1;
// edrk.Run_QTV = 0;
// edrk.Status_Sbor = 105;
// }
}
void sbor_shema_pusk_qtv(unsigned int t_start, unsigned int t_finish)
{
if (edrk.Sbor_Mode==t_start && edrk.Zaryad_OK == 1 && edrk.Status_UMP_Ok)
{
edrk.Run_QTV = 1;
}
if (edrk.Sbor_Mode>t_start && edrk.Sbor_Mode<t_finish )
{
edrk.Stage_Sbor = STAGE_SBOR_STATUS_QTV;
if ((edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 && edrk.Status_UMP_Ok))
edrk.Sbor_Mode = t_finish;
if (edrk.Sbor_Mode==(t_finish-1) && edrk.Status_UMP_Ok==0)
{
edrk.Run_QTV = 0;
edrk.Run_UMP = 0;
edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1;
edrk.errors.e11.bits.ERROR_READY_UMP_BEFORE_QTV |= 1;
edrk.Status_Sbor = 6;
}
}
if (edrk.Sbor_Mode>t_finish)
{
if (edrk.Zaryad_OK == 0 || edrk.Status_QTV_Ok==0)
{
edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1;
edrk.errors.e11.bits.ERROR_STATUS_QTV |= 1;
edrk.Run_QTV = 0;
edrk.Status_Sbor = 106;
}
}
}
void sbor_shema_stop_ump(unsigned int t_start, unsigned int t_finish)
{
// âêëþ÷àåì UMP
if (edrk.Sbor_Mode==t_start && edrk.Status_QTV_Ok == 1)
{
edrk.Run_UMP = 0;
}
if (edrk.Sbor_Mode>t_start && edrk.Sbor_Mode<t_finish)
{
edrk.Stage_Sbor = STAGE_SBOR_STATUS_UMP_OFF;
if (edrk.Status_UMP_Ok==0)
edrk.Sbor_Mode = t_finish;
// íåò çàðÿäà, îøèáêà
if (edrk.Sbor_Mode==(t_finish-1))
{
edrk.Run_UMP = 0;
edrk.Run_QTV = 0;
edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1;
// edrk.errors.e7.bits.UMP_NOT_ANSWER |= 1;
edrk.errors.e11.bits.ERROR_UMP_NOT_OFF |= 1;
edrk.Status_Sbor = 7;
}
}
if (edrk.Sbor_Mode>t_finish && edrk.Status_UMP_Ok==1)
{
edrk.Run_UMP = 0;
edrk.Run_Pred_Zaryad = 0;
edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1;
edrk.errors.e11.bits.ERROR_UMP_ON_AFTER |= 1;
edrk.Run_QTV = 0;
edrk.Status_Sbor = 107;
}
}
void sbor_shema_rascepitel_level_1(unsigned int t_start, unsigned int t_finish)
{
#if(RASCEPITEL_MANUAL_ALWAYS_ON==1)
if (edrk.Sbor_Mode==t_start && (edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 ))
{
edrk.Stage_Sbor = STAGE_SBOR_STATUS_RASCEPITEL_1;
// åñëè äðóãîé ÁÑ íå ñîáðàí, çàìûêàåì ðàñöåïèòåëü
if (optical_read_data.data.cmd.bit.ready_cmd != CODE_READY_CMD_READY2 )
{
edrk.Run_Rascepitel = 1;
edrk.Sbor_Mode = t_finish; // ïåðåïðûãíóëè äàëüøå
}
else
edrk.RunZahvatRascepitel = 1; // ïðîñèì äðóãîé ÁÑ ñáðîñèòü îáîðîòû è ðàçðåøèòü ïîäêëþ÷åíèå ðàñöåïèòåëÿ
}
if (edrk.Sbor_Mode>t_start && edrk.Sbor_Mode<t_finish && (edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 )
&& edrk.RunZahvatRascepitel && edrk.Run_Rascepitel==0)
{
edrk.Stage_Sbor = STAGE_SBOR_STATUS_RASCEPITEL_1;
// åñëè äðóãîé ÁÑ íå ñîáðàí, çàìûêàåì ðàñöåïèòåëü
// äðóãîé ÁÑ ñáðîñèë îáîðîòû åñëè îíè áûëè è ñíÿë ØÈÌ åñëè áûë
if (optical_read_data.data.cmd.bit.rascepitel_cmd == CODE_RASCEPITEL_CMD_ENABLE_ON_AND_THIS_ON ) // 01 - ìîæíî âêëþ÷àòü ðàñöåïèòåëü, ñâîé âêëþ÷åí
{
edrk.Run_Rascepitel = 1;
edrk.Sbor_Mode = t_finish; // ïåðåïðûãíóëè äàëüøå
}
}
#else
if (edrk.Sbor_Mode==t_start && (edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 ) && edrk.Status_Rascepitel_Ok==0)
{
edrk.Stage_Sbor = STAGE_SBOR_STATUS_RASCEPITEL_1;
// åñëè äðóãîé ÁÑ íå ñîáðàí, çàìûêàåì ðàñöåïèòåëü
if (optical_read_data.data.cmd.bit.ready_cmd != CODE_READY_CMD_READY2 )
{
edrk.Run_Rascepitel = 1;
edrk.Sbor_Mode = t_finish; // ïåðåïðûãíóëè äàëüøå
}
else
edrk.RunZahvatRascepitel = 1; // ïðîñèì äðóãîé ÁÑ ñáðîñèòü îáîðîòû è ðàçðåøèòü ïîäêëþ÷åíèå ðàñöåïèòåëÿ
}
//
if (edrk.Sbor_Mode>t_start && edrk.Sbor_Mode<t_finish && (edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 )
&& edrk.RunZahvatRascepitel && edrk.Status_Rascepitel_Ok==0 && edrk.Run_Rascepitel==0)
{
edrk.Stage_Sbor = STAGE_SBOR_STATUS_RASCEPITEL_1;
// åñëè äðóãîé ÁÑ íå ñîáðàí, çàìûêàåì ðàñöåïèòåëü
// äðóãîé ÁÑ ñáðîñèë îáîðîòû åñëè îíè áûëè è ñíÿë ØÈÌ åñëè áûë
if (optical_read_data.data.cmd.bit.rascepitel_cmd == CODE_RASCEPITEL_CMD_ENABLE_ON_AND_THIS_ON ) // 01 - ìîæíî âêëþ÷àòü ðàñöåïèòåëü, ñâîé âêëþ÷åí
{
edrk.Run_Rascepitel = 1;
edrk.Sbor_Mode = t_finish; // ïåðåïðûãíóëè äàëüøå
}
}
#endif
if (edrk.Sbor_Mode>t_finish)
{
if (edrk.Run_Rascepitel==0)
{
// íå äîæäàëèñü êîìàíäû íà âêëþ÷åíèå ñâîåãî ðàñöåïèòåëÿ
edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1;
edrk.errors.e11.bits.ERROR_RASCEPITEL_WAIT_CMD |= 1;
edrk.Run_QTV = 0;
edrk.Status_Sbor = 108;
// íå äîæäàëèñü ïîäòâåðæäåíèÿ îò äðóãîãî
if (edrk.RunZahvatRascepitel)
edrk.errors.e1.bits.NO_CONFIRM_ON_RASCEPITEL |= 1;
edrk.RunZahvatRascepitel = 0;
edrk.Run_Rascepitel = 0;
}
}
}
void sbor_shema_rascepitel_level_2(unsigned int t_start, unsigned int t_finish)
{
if (edrk.Sbor_Mode>t_start && edrk.Sbor_Mode<t_finish)
{
edrk.Stage_Sbor = STAGE_SBOR_STATUS_RASCEPITEL_2;
#if(RASCEPITEL_MANUAL_ALWAYS_ON==1)
edrk.Sbor_Mode = t_finish; // ïåðåïðûãíóëè äàëüøå
#else
if ( (edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 )
&& edrk.Status_Rascepitel_Ok==1 && edrk.Run_Rascepitel==1)
{
// äîæäàëèñü âêëþ÷åíèÿ ðàñöåïèòåëÿ è ïðûãíóëè äàëüøå
edrk.Sbor_Mode = t_finish; // ïåðåïðûãíóëè äàëüøå
}
if (edrk.Sbor_Mode==(t_finish-1) && edrk.Status_Rascepitel_Ok==0 && edrk.Run_Rascepitel==1)
{
// íå äîæäàëèñü ïîäòâåðæäåíèÿ íà âêëþ÷åíèå ñâîåãî ðàñöåïèòåëÿ
edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1;
edrk.Run_QTV = 0;
edrk.Status_Sbor = 9;
edrk.errors.e6.bits.RASCEPITEL_ERROR_NOT_ANSWER |= 1;
edrk.RunZahvatRascepitel = 0;
edrk.Run_Rascepitel = 0;
}
#endif
}
if (edrk.Sbor_Mode>t_finish && edrk.Status_Rascepitel_Ok==0)
{
// ðàñöåïèòåëü âûêëþ÷èëñÿ, à íå äîëæåí áûë
edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1;
edrk.Run_QTV = 0;
edrk.Status_Sbor = 109;
// edrk.errors.e6.bits.RASCEPITEL_ERROR_NOT_ANSWER |= 1;
edrk.errors.e11.bits.ERROR_RASCEPITEL_ON_AFTER |= 1;
edrk.RunZahvatRascepitel = 0;
edrk.Run_Rascepitel = 0;
}
//
// ïî ñèãíàëó edrk.RunZahvatRascepitel äîëæåí òîò ÁÑ ñáðîñèòü îáîðîòû è ïîäòâåðäèòü âîçìîæíîñòü âêëþ÷åíèå ðàñöåïèòåëÿ
//
// if (edrk.Sbor_Mode>t_start && edrk.Sbor_Mode<t_finish && (edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 )
// && edrk.Status_Rascepitel_Ok==1 && edrk.Run_Rascepitel==1)
// {
// // äîæäàëèñü âêëþ÷åíèÿ ðàñöåïèòåëÿ è ïðûãíóëè äàëüøå
// edrk.Sbor_Mode = t_finish; // ïåðåïðûãíóëè äàëüøå
// }
//
////
// // ïî ñèãíàëó edrk.RunZahvatRascepitel äîëæåí òîò ÁÑ ñáðîñèòü îáîðîòû è ïîäòâåðäèòü âîçìîæíîñòü âêëþ÷åíèå ðàñöåïèòåëÿ
// if (edrk.Sbor_Mode==(t_finish-1) && (edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 )
// && edrk.RunZahvatRascepitel && edrk.Status_Rascepitel_Ok==0 && edrk.Run_Rascepitel==0)
// {
// //
//// if (optical_read_data.data.cmd.bit.rascepitel_cmd != CODE_RASCEPITEL_CMD_ENABLE_ON_AND_THIS_ON ) // 01 - ìîæíî âêëþ÷àòü ðàñöåïèòåëü, ñâîé âêëþ÷åí
// {
// // íå äîæäàëèñü ïîäòâåðæäåíèÿ íà âêëþ÷åíèå ñâîåãî ðàñöåïèòåëÿ
// edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1;
// edrk.Run_QTV = 0;
// edrk.Status_Sbor = 8;
// edrk.errors.e1.bits.NO_CONFIRM_ON_RASCEPITEL |= 1;
// edrk.RunZahvatRascepitel = 0;
// edrk.Run_Rascepitel = 0;
//// edrk.Run_Rascepitel = 0;
// }
// }
}
void sbor_shema_rascepitel_level_3(unsigned int t_start, unsigned int t_finish)
{
// òóò æäåì âêëþ÷åíèÿ ðàñöåïèòåëÿ
if (edrk.Sbor_Mode>t_start && edrk.Sbor_Mode<t_finish)
{
edrk.Stage_Sbor = STAGE_SBOR_STATUS_RASCEPITEL_3;
if (edrk.Status_Rascepitel_Ok==1)
{
// Ðàñöåïèòåëü âêëþ÷èëñÿ!
// ìîæíî ïåðåïðûãèâàòü â êîíåö
edrk.Sbor_Mode = t_finish; // ïåðåïðûãíóëè äàëüøå
edrk.RunZahvatRascepitel = 0;
}
// edrk.Run_Rascepitel = 1;
}
// if (edrk.Sbor_Mode==(t_finish-1) && (edrk.Zaryad_OK == 0 || edrk.Status_QTV_Ok==0 || edrk.Status_Rascepitel_Ok==0))
// {
// edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1;
// edrk.Run_QTV = 0;
//// edrk.Run_Rascepitel = 0;
// edrk.RunZahvatRascepitel = 0;
// edrk.Status_Sbor = 10;
// edrk.Run_Rascepitel = 0;
//
// }
}
void sbor_shema_rascepitel_level_4(unsigned int t_start, unsigned int t_finish)
{
if (edrk.Sbor_Mode>t_start && edrk.Sbor_Mode<t_finish && (edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 && edrk.Status_Rascepitel_Ok))
{
edrk.Stage_Sbor = STAGE_SBOR_STATUS_RASCEPITEL_4;
if (optical_read_data.data.cmd.bit.ready_cmd==CODE_READY_CMD_READY1TO2) // òîò ÁÑ ñîáèðàåòñÿ åùå
{
// îæèäàåì äîñáîðà âòîðîãî ÁÑ
// íî ðàñöåïèòåëü óæå âêëþ÷èëñÿ.
if (optical_read_data.data.cmd.bit.rascepitel_cmd == CODE_RASCEPITEL_CMD_ENABLE_ON_AND_THIS_ON)
edrk.Sbor_Mode = t_finish; // ïåðåïðûãíóëè äàëüøå
}
else
{
edrk.Sbor_Mode = t_finish; // ïåðåïðûãíóëè äàëüøå
}
}
// if (edrk.Sbor_Mode>t_finish)
// {
// if (edrk.Status_Rascepitel_Ok==0)
// {
// edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1;
// edrk.Run_QTV = 0;
// edrk.RunZahvatRascepitel = 0;
// edrk.Status_Sbor = 9;
// edrk.Run_Rascepitel = 0;
//
// }
//
// }
}
void sbor_shema_wait_ready_another(unsigned int t_start, unsigned int t_finish)
{
if (edrk.Sbor_Mode>t_start && edrk.Sbor_Mode<t_finish && (edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 && edrk.Status_Rascepitel_Ok))
{
edrk.Stage_Sbor = STAGE_SBOR_STATUS_WAIT_READY_ANOTHER;
if (optical_read_data.data.cmd.bit.ready_cmd!=CODE_READY_CMD_READY1TO2)
{
edrk.Sbor_Mode = t_finish; // ïåðåïðûãíóëè äàëüøå
}
if (edrk.Sbor_Mode==(t_finish-1) && optical_read_data.data.cmd.bit.ready_cmd==CODE_READY_CMD_READY1TO2)
{
edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1;
edrk.errors.e1.bits.ANOTHER_BS_VERY_LONG_WAIT |= 1;
edrk.Run_QTV = 0;
// edrk.Run_Rascepitel = 0;
edrk.RunZahvatRascepitel = 0;
edrk.Status_Sbor = 11;
edrk.Run_Rascepitel = 0;
}
}
}
void sbor_shema_wait_finish(unsigned int t_start, unsigned int t_finish)
{
if (edrk.Sbor_Mode>t_start && (edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 && edrk.Status_Rascepitel_Ok))
{
edrk.Stage_Sbor = STAGE_SBOR_STATUS_FINISH;
edrk.SborFinishOk = 1;
// allow_discharge = 1;
}
if (edrk.Sbor_Mode>t_finish && (edrk.SborFinishOk) )
{
edrk.time_wait_sbor = 0;
}
else
edrk.Sbor_Mode++;
}
///////////////////////////////////////////////
///////////////////////////////////////////////
///////////////////////////////////////////////
#define TIME_WAIT_RELE_UMP_ON 20 //2 sec
#define TIME_WAIT_RELE_UMP_OFF 20 //2 sec
#define TIME_WAIT_ANSWER_UMP_ON 150 //15 sec
#define TIME_WAIT_ANSWER_UMP_OFF 40 //4 sec
#define TIME_PAUSE_AFTER_GET_READY_UMP 50 // 5 sec
///////////////////////////////////////////////
int ump_on_off(unsigned int flag)
{
static unsigned int time_wait_rele_on_ump=0;
static unsigned int time_wait_rele_off_ump=0;
static unsigned int time_wait_answer_on_ump=0;
static unsigned int time_wait_answer_off_ump=0;
int cmd_ump=0;//,cmd_p2=0;
static int UMP_Ok = 0;
static int prev_error = 0, count_ready_upm = 0; //, flag_enable_on_ump = 0;
cmd_ump = 0;
// cmd_p2 = 0;
if ( flag==1 && edrk.summ_errors==0)
{
cmd_ump = 1;
}
else
{
cmd_ump = 0;
}
edrk.cmd_to_ump = cmd_ump;
if (cmd_ump)
{
// if ((pause_detect_error(&time_wait_rele_on_qtv,TIME_WAIT_RELE_UMP_ON,1)==0) && edrk.from_shema.bits.UMP_ON_OFF==0)
// {
// edrk.to_shema.bits.QTV_ON_OFF = 1;
// }
// else
// æäåì ãîòîâíîñòü!
if (edrk.from_shema_filter.bits.READY_UMP == 1)
{
// äàåì çàäåðæêó TIME_PAUSE_AFTER_GET_READY_UMP
if (count_ready_upm<TIME_PAUSE_AFTER_GET_READY_UMP)
count_ready_upm++;
else
edrk.flag_enable_on_ump = 1;
}
else
count_ready_upm = 0;
if (edrk.flag_enable_on_ump)
{
edrk.sbor_wait_ump2 = 1;
edrk.to_shema.bits.UMP_ON_OFF = 1;
if (pause_detect_error(&time_wait_answer_on_ump, TIME_WAIT_ANSWER_UMP_ON, 1)==0)
{
edrk.sbor_wait_ump1 = 1;
if (edrk.from_shema_filter.bits.UMP_ON_OFF==1)
UMP_Ok = 1;
}
else
{
edrk.sbor_wait_ump1 = 0;
if (edrk.from_shema_filter.bits.UMP_ON_OFF==0)
{
edrk.errors.e7.bits.UMP_NOT_ANSWER |= 1;
UMP_Ok = 0;
}
}
}
else
{
edrk.sbor_wait_ump2 = 0;
}
time_wait_rele_off_ump = 0;
time_wait_answer_off_ump = 0;
}
else
{
count_ready_upm = 0;
UMP_Ok = 0;
time_wait_rele_on_ump = 0;
time_wait_answer_on_ump = 0;
edrk.to_shema.bits.UMP_ON_OFF = 0;
edrk.flag_enable_on_ump = 0;
edrk.sbor_wait_ump2 = 0;
if (pause_detect_error(&time_wait_answer_off_ump, TIME_WAIT_ANSWER_UMP_OFF, 1)==0)
{
edrk.sbor_wait_ump1 = 1;
}
else
{
edrk.sbor_wait_ump1 = 0;
// îòêëþ÷èëè äåòåêò ÷òî UMP âäðóã âêëþ÷èëñÿ!!!
if (edrk.from_shema_filter.bits.UMP_ON_OFF==1)
edrk.errors.e7.bits.UMP_NOT_ANSWER |= 1;
}
if (prev_error!=edrk.summ_errors && edrk.summ_errors)
{
if (pause_detect_error(&time_wait_rele_off_ump,TIME_WAIT_RELE_UMP_OFF,1)==1)
time_wait_rele_off_ump = 0;
}
}
prev_error = edrk.summ_errors;
return (UMP_Ok);
}
///////////////////////////////////////////////
///////////////////////////////////////////////
///////////////////////////////////////////////
#define TIME_WAIT_RELE_RASCEPITEL_ON 10 //2 sec
#define TIME_WAIT_RELE_RASCEPITEL_OFF 10 //2 sec
#define TIME_WAIT_ANSWER_RASCEPITEL_ON 100 //15 sec
#define TIME_WAIT_ANSWER_RASCEPITEL_ON_BS1 100 //15 sec
#define TIME_WAIT_ANSWER_RASCEPITEL_ON_BS2 150 //15 sec
#define TIME_WAIT_ANSWER_RASCEPITEL_OFF 100 //15 sec
#define TIME_WAIT_LEVEL_RASCEPITEL_ON_OFF 50 //5 sec
#define TIME_WAIT_LEVEL_RASCEPITEL_ON_OFF_BS1 50 //5 sec
#define TIME_WAIT_LEVEL_RASCEPITEL_ON_OFF_BS2 100 //7.5 sec
#define TIME_WAIT_PEREHOD_SOST_ON_OFF 100 //15 sec
///////////////////////////////////////////////
void rascepitel_on_off(unsigned int flag, int *status_perehod, int *status_on_off, int *final_status_on_off)
{
static unsigned int time_wait_rele_on=0;
static unsigned int time_wait_rele_off=0;
static unsigned int time_wait_answer_on=0;
static unsigned int time_wait_answer_off=0;
static unsigned int time_wait_level_on=0;
static unsigned int time_wait_level_off=0;
static unsigned int time_wait_perehod_sost=0;
int cmd_rele=0, r;//,cmd_p2=0;
static int Rele_Ok = 0, filter_sost_rascepitel = 0;
static int prev_error = 0, perehod_sost = 0, flag_wait_break_perehod_sost = 0, prev_cmd_rele = 0;
cmd_rele = 0;
// cmd_p2 = 0;
if ( flag==1 && edrk.errors.e6.bits.RASCEPITEL_ERROR_NOT_ANSWER == 0)
{
cmd_rele = 1;
}
else
{
cmd_rele = 0;
}
edrk.cmd_to_rascepitel = cmd_rele;
if (cmd_rele)
{
if (perehod_sost && cmd_rele!=prev_cmd_rele && flag_wait_break_perehod_sost==0)
{
flag_wait_break_perehod_sost = 1;
time_wait_perehod_sost = 0;
}
edrk.to_ing.bits.RASCEPITEL_OFF = 0;
if (flag_wait_break_perehod_sost)
{
if (pause_detect_error(&time_wait_perehod_sost,TIME_WAIT_PEREHOD_SOST_ON_OFF,1)==1)
flag_wait_break_perehod_sost = 0;
}
if (flag_wait_break_perehod_sost==0)
{
if ((pause_detect_error(&time_wait_rele_on,TIME_WAIT_RELE_RASCEPITEL_ON,1)==0)/* && edrk.from_ing1.bits.RASCEPITEL_ON==0*/)
{
perehod_sost = 1;
edrk.to_ing.bits.RASCEPITEL_ON = 1;
}
else
edrk.to_ing.bits.RASCEPITEL_ON = 0;
if (edrk.flag_second_PCH==0)
r = pause_detect_error(&time_wait_answer_on,TIME_WAIT_ANSWER_RASCEPITEL_ON_BS1,1);
else
if (edrk.flag_second_PCH==1)
r = pause_detect_error(&time_wait_answer_on,TIME_WAIT_ANSWER_RASCEPITEL_ON_BS2,1);
else
r = 0;
if (r==0)
{
}
else
{
if (edrk.from_ing1.bits.RASCEPITEL_ON==1)
Rele_Ok = 1;
#if(RASCEPITEL_MANUAL_ALWAYS_ON==1)
Rele_Ok = 1;
#else
if (edrk.from_ing1.bits.RASCEPITEL_ON==0)
{
edrk.errors.e6.bits.RASCEPITEL_ERROR_NOT_ANSWER |= 1;
Rele_Ok = 0;
}
#endif
perehod_sost = 0;
}
time_wait_rele_off = 0;
time_wait_answer_off = 0;
}
}
else
{
Rele_Ok = 0;
time_wait_rele_on = 0;
time_wait_answer_on = 0;
if (perehod_sost && cmd_rele!=prev_cmd_rele && flag_wait_break_perehod_sost==0)
{
flag_wait_break_perehod_sost = 1;
time_wait_perehod_sost = 0;
}
edrk.to_ing.bits.RASCEPITEL_ON = 0;
if (flag_wait_break_perehod_sost)
{
if (pause_detect_error(&time_wait_perehod_sost,TIME_WAIT_PEREHOD_SOST_ON_OFF,1)==1)
flag_wait_break_perehod_sost = 0;
}
if (flag_wait_break_perehod_sost==0)
{
if (pause_detect_error(&time_wait_rele_off,TIME_WAIT_RELE_RASCEPITEL_OFF,1)==0/* && edrk.from_ing1.bits.RASCEPITEL_ON==1*/)
{
edrk.to_ing.bits.RASCEPITEL_OFF = 1;
perehod_sost = 1;
}
else
edrk.to_ing.bits.RASCEPITEL_OFF = 0;
if (pause_detect_error(&time_wait_answer_off,TIME_WAIT_ANSWER_RASCEPITEL_OFF,1)==0)
{
}
else
{
#if(RASCEPITEL_MANUAL_ALWAYS_ON==1)
#else
if (edrk.from_ing1.bits.RASCEPITEL_ON == 1)
edrk.errors.e6.bits.RASCEPITEL_ERROR_NOT_ANSWER |= 1;
#endif
perehod_sost = 0;
}
}
// if (prev_error!=edrk.summ_errors && edrk.summ_errors)
// {
// if (pause_detect_error(&time_wait_rele_off,TIME_WAIT_RELE_RASCEPITEL_OFF,1)==1)
// time_wait_rele_off = 0;
// }
}
if (edrk.from_ing1.bits.RASCEPITEL_ON==1)
{
time_wait_level_off = 0;
if (edrk.flag_second_PCH==0)
{
if (pause_detect_error(&time_wait_level_on,TIME_WAIT_LEVEL_RASCEPITEL_ON_OFF_BS1,1)==1)
filter_sost_rascepitel = 1;
}
else
{
if (pause_detect_error(&time_wait_level_on,TIME_WAIT_LEVEL_RASCEPITEL_ON_OFF_BS2,1)==1)
filter_sost_rascepitel = 1;
}
}
else
{
time_wait_level_on = 0;
if (pause_detect_error(&time_wait_level_off,TIME_WAIT_LEVEL_RASCEPITEL_ON_OFF,1)==1)
filter_sost_rascepitel = 0;
}
prev_error = edrk.summ_errors;
prev_cmd_rele = cmd_rele;
*status_perehod = perehod_sost;
if (filter_sost_rascepitel && perehod_sost==0 )
*final_status_on_off = 1;
// *status_on_off = 1;
if (filter_sost_rascepitel==0 && perehod_sost==0 )
*final_status_on_off = 0;
*status_on_off = filter_sost_rascepitel;
// if (perehod_sost==1)
// *status_on_off = 2;
return;
}
///////////////////////////////////////////////
unsigned int sbor_shema(int mode)
{
// static unsigned int time_wait_sbor = 0;
static int prev_ready_final = 0;
static unsigned int time_wait_razbor = 0;
static unsigned int allow_discharge = 0, may_be_discharge=0;
int enable_sbor;
static unsigned int t1,t2, delta_t, first_run = 1, add_t1 = 0;
// static int Run_Pred_Zaryad;
enable_sbor = (edrk.zadanie.ZadanieU_Charge>10) && edrk.Status_Ready.bits.ready1;
if (mode && edrk.summ_errors==0 && enable_sbor==0)
{
edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1;
edrk.errors.e11.bits.ERROR_DISABLE_SBOR |= 1;
// ðàçáîð
edrk.AutoStartPump = 0;
edrk.Sbor_Mode = 0;
edrk.Razbor_Mode = 0;
edrk.time_wait_sbor = 0;
time_wait_razbor = 0;
edrk.Run_Pred_Zaryad = 0;
edrk.Zaryad_OK = 0;
edrk.Run_QTV = 0;
edrk.Run_UMP = 0;
edrk.SborFinishOk = 0;
edrk.RunZahvatRascepitel = 0;
// edrk.Run_Rascepitel = 0;
edrk.Status_Sbor = 1;
first_run = 1;
edrk.enter_to_pump_stage = 0;
return (edrk.Sbor_Mode);
}
// ñáîð ñõåìû
if (mode && edrk.summ_errors==0 && enable_sbor)
{
if (pause_detect_error(&edrk.time_wait_sbor,TIME_WAIT_SBOR,1))
{
// if (edrk.SborFinishOk==0)
edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1;
edrk.errors.e11.bits.ERROR_VERY_LONG_SBOR |= 1;
}
if (first_run)
{
if (edrk.flag_another_bs_first_ready12==1 && edrk.flag_this_bs_first_ready12==0)
{
// äðóãîé ÁÑ óæå ñîáèðàåòñÿ?
add_t1 = 80; // ðàçáåæêà 12 ñåê
}
else
if (edrk.flag_another_bs_first_ready12==0 && edrk.flag_this_bs_first_ready12==1)
{
// äðóãîé ÁÑ íå ñîáèðàåòñÿ?
add_t1 = 5; // ðàçáåæêà 1 ñåê
}
else
if (edrk.flag_this_bs_first_ready12==0 && edrk.flag_another_bs_first_ready12==0)
{
// òóò íåïîíÿòíî êàê îêàçàëèñü
if (edrk.flag_second_PCH == 1)
add_t1 = 120; // ðàçáåæêà 18 ñåê
else
add_t1 = 80; // ðàçáåæêà 7 ñåê
}
// if (optical_read_data.data.cmd.bit.ready_cmd==CODE_READY_CMD_READY1TO2 && edrk.flag_second_PCH == 1)
// {
// // äðóãîé ÁÑ óæå ñîáèðàåòñÿ?
// add_t1 = 150; // ðàçáåæêà 15 ñåê
// }
// else
// {
// if (edrk.flag_second_PCH == 0)
// add_t1 = 0;
// else
// add_t1 = 70; // ðàçáåæêà 7 ñåê
// }
first_run = 0;
}
// ïóñê íàñîñà
t1 = 10 + add_t1;
delta_t = 300;//200;
t2 = t1 + delta_t;
sbor_shema_pusk_nasos(t1,t2);//350
t1 = t2+30;//380
delta_t = 700;
t2 = t1 + delta_t;
sbor_shema_pusk_zaryad(t1,t2);//1080
t1 = t2+10;//1090
delta_t = 750+750+300+600;//2400 äîëãî æäåì âäðóã óìï çàíÿò íà âòîðîé áñ
t2 = t1 + delta_t;
sbor_shema_pusk_ump(t1,t2);//3490
t1 = t2+30; //3520 æäåì 3 ñåê åùå
delta_t = 200;
t2 = t1 + delta_t;
sbor_shema_pusk_qtv(t1,t2);//3720
t1 = t2;
delta_t = 150;
t2 = t1 + delta_t;
sbor_shema_stop_ump(t1,t2);//3870
// åñëè äðóã ÁÑ íå ñîáðàí, òî ðàçðåøàåì ñâîå ïîäêëþ÷åíèå ðàñöåïèòåëÿ è ïåðåõîä íà tfinish
// èíà÷å äàåì çàïðîñ è æäåì îò tstart äî tfinish ðàçðåøåíèå íà ïîäêëþ÷åíèå ðàñöåïèòåëÿ è ñðàçó ðàçðåøàåì åãî ïîäêëþ÷åíèå
// â êîíöå äîëæåí þûòü ñèãíàë íà âêëþ÷åíèå ðàñöåïèòåëÿ èíà÷å îøèáêà!
t1 = t2;
delta_t = 250;
t2 = t1 + delta_t;
sbor_shema_rascepitel_level_1(t1,t2);//4120
// æäåì âêëþ÷åíèÿ ðàñöåïèòåëÿ äî tfinish
// èëè äî tfinish æäåì ïîäòâåðæäåíèÿ çàõâàòà
t1 = t2;
delta_t = 300;
t2 = t1 + delta_t;
sbor_shema_rascepitel_level_2(t1,t2);//4420
t1 = t2;
delta_t = 200;
t2 = t1 + delta_t;
sbor_shema_rascepitel_level_3(t1,t2);//4620
// íàø ðàñöåïèòåëü âêëþ÷èëñÿ, íî âòîðîé ÁÑ òîæå ñîáèðàåòñÿ, ïîýòîìó òóò æäåì ïîêà îí âêëþ÷èò ñâîé ðàñöåïèòåëü
// èíà÷å ñðàçó tfinish
t1 = t2;
delta_t = 300;
t2 = t1 + delta_t;
sbor_shema_rascepitel_level_4(t1,t2);//4920
// æäåì äî tfinish ïîäòâåðæäåíèÿ îêîí÷àíèÿ ñáîðà îò äðóãîãî ÁÑ
// åñëè íå äîæäàëèñü, òî îøèáêà
t1 = t2;
delta_t = 1800;
t2 = t1 + delta_t;
sbor_shema_wait_ready_another(t1,t2);//6720
t1 = t2;
delta_t = 50;
t2 = t1 + delta_t;
sbor_shema_wait_finish(t1,t2);//6770
edrk.Razbor_Mode = 0;
edrk.RazborNotFinish = 0;
edrk.RunUnZahvatRascepitel = 0;
if (edrk.Zaryad_OK)
may_be_discharge = 1;
}
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
// ðàçáîð ñõåìû
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
else
{
first_run = 1;
edrk.enter_to_pump_stage = 0;
// ðàçáîð ñõåìû
if (edrk.Razbor_Mode==0)
edrk.RazborNotFinish = 1;
if (edrk.Status_QTV_Ok==0 && edrk.Status_UMP_Ok==0 && may_be_discharge && edrk.Razbor_Mode>100)
{
allow_discharge = 1;
may_be_discharge = 0;
}
edrk.AutoStartPump = 0;
edrk.Sbor_Mode = 0;
edrk.time_wait_sbor = 0;
edrk.Zaryad_OK = 0;
edrk.Run_QTV = 0;
edrk.Run_UMP = 0;
edrk.SborFinishOk = 0;
edrk.Run_Pred_Zaryad = 0;
edrk.RunZahvatRascepitel = 0;
if (edrk.Razbor_Mode==10 && edrk.Status_QTV_Ok==1)
{
//
edrk.errors.e2.bits.ERROR_RAZBOR_SHEMA |= 1;
}
if (edrk.Run_Rascepitel && edrk.Razbor_Mode==20 && edrk.Status_QTV_Ok==0 && edrk.Status_Rascepitel_Ok==0)
{
// íà ðàñöåïèòåëü áûëà ïîäàíà êîìàíäà íà ñâåäåíèå, íî îí íå ñâåëñÿ ïî÷åìó-òî, íó è ëàäíî
edrk.Run_Rascepitel = 0;
edrk.Razbor_Mode=1000; // ïåðåïðûãíóëè â êîíåö ðàçáîðà
}
if (edrk.Run_Rascepitel && edrk.Razbor_Mode==30 && edrk.Status_QTV_Ok==0 && edrk.Status_Rascepitel_Ok==1)
{
// åñëè äðóãîé ÁÑ íå ñîáðàí, ðàçìûêàåì ðàñöåïèòåëü áåç âñÿêèõ çàïðîñîâ
if (optical_read_data.data.cmd.bit.ready_cmd != CODE_READY_CMD_READY2 )
edrk.Run_Rascepitel = 0;
else
edrk.RunUnZahvatRascepitel = 1; // ïðîñèì äðóãîé ÁÑ îñòàíîâèòüñÿ
}
if (edrk.Razbor_Mode>40 && edrk.Razbor_Mode<390 && (edrk.Status_QTV_Ok==0)
&& edrk.RunUnZahvatRascepitel && edrk.Status_Rascepitel_Ok==1)
{
// åñëè äðóãîé ÁÑ íå ñîáðàí, ðàçìûêàåì ðàñöåïèòåëü
// äðóãîé ÁÑ ñáðîñèë îáîðîòû åñëè îíè áûëè è ñíÿë ØÈÌ åñëè áûë
if (optical_read_data.data.cmd.bit.rascepitel_cmd == CODE_RASCEPITEL_CMD_ENABLE_ON_AND_THIS_ON ) // 01 - ìîæíî âûêëþ÷àòü ðàñöåïèòåëü, ñâîé âêëþ÷åí
{
edrk.Run_Rascepitel = 0;
edrk.RunUnZahvatRascepitel = 0;
edrk.Razbor_Mode = 390;
}
}
// åñëè ðàñöåïèòåëü îòêëþ÷åí, òî ñðàçó èäåì â êîíåö
if (edrk.Razbor_Mode>40 && edrk.Razbor_Mode<600 && (edrk.Status_QTV_Ok==0)
&& edrk.RunUnZahvatRascepitel==0 && edrk.Run_Rascepitel==0)
{
if (edrk.Status_Rascepitel_Ok == 0 )
{
edrk.Razbor_Mode = 600;
}
}
if (edrk.Razbor_Mode>390 && (edrk.Status_QTV_Ok==0)
&& edrk.RunUnZahvatRascepitel && edrk.Status_Rascepitel_Ok==1 && edrk.Run_Rascepitel)
{
if (optical_read_data.data.cmd.bit.rascepitel_cmd != CODE_RASCEPITEL_CMD_ENABLE_ON_AND_THIS_ON ) // íå äîæäàëèñü ïîòâåðæäåíèÿ âîçìîæíîñòè îòêëþ÷åíèÿ ðàñöåïèòåëÿ ñâîåãî
{
edrk.RunUnZahvatRascepitel = 0;
edrk.errors.e1.bits.NO_CONFIRM_ON_RASCEPITEL |= 1;
edrk.errors.e2.bits.ERROR_RAZBOR_SHEMA |= 1;
}
}
//
// if (edrk.Razbor_Mode==400 && (edrk.Status_QTV_Ok==0)
// && edrk.RunUnZahvatRascepitel && edrk.Status_Rascepitel_Ok==1)
// {
// // åñëè äðóãîé ÁÑ íå ñîáðàí, ðàçìûêàåì ðàñöåïèòåëü
// // äðóãîé ÁÑ ñáðîñèë îáîðîòû åñëè îíè áûëè è ñíÿë ØÈÌ åñëè áûë
// if (optical_read_data.data.cmd.bit.rascepitel_cmd != CODE_RASCEPITEL_CMD_ENABLE_ON_AND_THIS_ON ) // 01 - ìîæíî âûêëþ÷àòü ðàñöåïèòåëü, ñâîé âêëþ÷åí
// {
//// edrk.Run_Rascepitel = 0;
// edrk.RunUnZahvatRascepitel = 0;
// edrk.errors.e1.bits.NO_CONFIRM_ON_RASCEPITEL |= 1;
// edrk.errors.e2.bits.ERROR_RAZBOR_SHEMA |= 1;
//
// }
// }
//
if (edrk.Razbor_Mode==600 && edrk.Status_QTV_Ok==0
&& edrk.Run_Rascepitel == 0
&& edrk.Status_Rascepitel_Ok==1 )
{
#if(RASCEPITEL_MANUAL_ALWAYS_ON==1)
#else
// ðàñöåïèòåëü íå îòêëþ÷èëñÿ!
if (edrk.Run_Rascepitel_from_RS==0) // è íåò ïðÿìîãî óïðàâëåíèÿ îò rs232?
{
edrk.errors.e6.bits.RASCEPITEL_ERROR_NOT_ANSWER |= 1;
edrk.errors.e2.bits.ERROR_RAZBOR_SHEMA |= 1;
}
#endif
}
#if(RASCEPITEL_MANUAL_ALWAYS_ON==1)
edrk.RazborNotFinish = 0;
edrk.RunUnZahvatRascepitel = 0;
edrk.Razbor_Mode=650; // ïåðåïðûãíóëè â êîíåö ðàçáîðà
#else
// âñå îê, âñå îòêëþ÷èëîñü, ðàçáîð çàâåðøåí
if (edrk.Run_Rascepitel==0 && edrk.Razbor_Mode>20 && edrk.Status_QTV_Ok==0 && (edrk.Status_Rascepitel_Ok==0 || edrk.Run_Rascepitel_from_RS==1) )
{
edrk.RazborNotFinish = 0;
edrk.RunUnZahvatRascepitel = 0;
edrk.Razbor_Mode=650; // ïåðåïðûãíóëè â êîíåö ðàçáîðà
}
#endif
// edrk.Run_Rascepitel = 0;
if (edrk.Razbor_Mode>650)
{
time_wait_razbor = 0;
}
else
edrk.Razbor_Mode++;
}
if (edrk.errors.e7.bits.ERROR_SBOR_SHEMA)
{
// ðàçáîð
edrk.AutoStartPump = 0;
edrk.Sbor_Mode = 0;
edrk.Run_Pred_Zaryad = 0;
edrk.time_wait_sbor = 0;
edrk.Zaryad_OK = 0;
edrk.Run_QTV = 0;
edrk.Run_UMP = 0;
edrk.SborFinishOk = 0;
edrk.RunZahvatRascepitel = 0;
// edrk.Run_Rascepitel = 0; // îòêëþ÷àåì ðàñöåïèòåëü, õîòÿ âîçìîæíî è íåëüçÿ ýòî äåëàòü????
}
//////////////////////////////////////
//////////////////////////////////////
edrk.Status_Charge = zaryad_on_off(edrk.Run_Pred_Zaryad);
if (control_station.active_array_cmd[CONTROL_STATION_CMD_DISABLE_ON_UMP]==1 || edrk.Status_Ready.bits.ImitationReady2)
{
edrk.Status_UMP_Ok = edrk.Run_UMP;
edrk.Zaryad_UMP_Ok = 1;
edrk.to_shema.bits.UMP_ON_OFF = 0;
}
else
{
edrk.Status_UMP_Ok = ump_on_off(edrk.Run_UMP);
edrk.Zaryad_UMP_Ok = detect_zaryad_ump();
}
if (control_station.active_array_cmd[CONTROL_STATION_CMD_DISABLE_ON_QTV]==1 || edrk.Status_Ready.bits.ImitationReady2)
{
edrk.Status_QTV_Ok = edrk.Run_QTV;
edrk.to_shema.bits.QTV_ON_OFF = 0;
edrk.to_shema.bits.QTV_ON = 0;
}
else
edrk.Status_QTV_Ok = qtv_on_off(edrk.Run_QTV);
rascepitel_on_off ( edrk.Run_Rascepitel || edrk.Run_Rascepitel_from_RS,
&edrk.Status_Perehod_Rascepitel,
&edrk.Status_Rascepitel_Ok,
&edrk.Final_Status_Rascepitel
);
//////////////////////////////////////
//////////////////////////////////////
//////////////////////////////////////
//////////////////////////////////////
if (control_station.active_array_cmd[CONTROL_STATION_CMD_MANUAL_DISCHARGE]==1 && edrk.SborFinishOk==0)
edrk.ManualDischarge = 1;
else
edrk.ManualDischarge = 0;
if (allow_discharge && edrk.SborFinishOk == 0)
{
edrk.Discharge = 1;
allow_discharge = 0;
}
if ( edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 && edrk.Status_Rascepitel_Ok)
edrk.Status_Ready.bits.ready7 = 1;
else
edrk.Status_Ready.bits.ready7 = 0;
// if (edrk.StatusPumpFanAll)
// edrk.Status_Ready.bits.ready1 = 1;
// else
// edrk.Status_Ready.bits.ready1 = 0;
if (edrk.Run_Pred_Zaryad)
edrk.Status_Ready.bits.ready2 = 1;
else
edrk.Status_Ready.bits.ready2 = 0;
if (edrk.Zaryad_OK)
edrk.Status_Ready.bits.ready3 = 1;
else
edrk.Status_Ready.bits.ready3 = 0;
if (edrk.Status_QTV_Ok)
edrk.Status_Ready.bits.ready4 = 1;
else
edrk.Status_Ready.bits.ready4 = 0;
if (edrk.SborFinishOk || edrk.Status_Ready.bits.ImitationReady2==1)
edrk.Status_Ready.bits.ready5 = 1;
else
edrk.Status_Ready.bits.ready5 = 0;
if (edrk.ms.ready3 || edrk.ms.another_bs_maybe_on==0)
edrk.Status_Ready.bits.ready6 = 1;
else
edrk.Status_Ready.bits.ready6 = 0;
if (edrk.Status_Ready.bits.ready5==1 && edrk.Status_Ready.bits.ready6==1 && edrk.Status_Ready.bits.MasterSlaveActive)
{
if (edrk.Status_Ready.bits.ImitationReady2)
edrk.Status_Ready.bits.preImitationReady2 = 1;
edrk.Status_Ready.bits.ready_final = 1;
}
else
{
edrk.Status_Ready.bits.ready_final = 0;
edrk.Status_Ready.bits.preImitationReady2 = 0;
}
if (edrk.Status_Ready.bits.ready_final && prev_ready_final==0)
edrk.count_sbor++;
prev_ready_final = edrk.Status_Ready.bits.ready_final;
return (edrk.Sbor_Mode);
}
unsigned int imit_signals_rascepitel(unsigned int *counter, unsigned int max_pause, unsigned int s, unsigned int cmd_clear)
{
if (cmd_clear==1)
{
(*counter) = 0;
return 0;
}
if (s)
{
if ((*counter)>=max_pause)
return 1;
else
(*counter)++;
return 0;
}
if (s==0)
{
if ((*counter)==0)
return 0;
else
(*counter)--;
return 1;
}
return 0;
}
#define TIME_WAIT_OFF_BLOCK_KEY 100
void auto_block_key_on_off(void)
{
static unsigned int count_err = TIME_WAIT_OFF_BLOCK_KEY;
if (edrk.SumSbor && edrk.enter_to_pump_stage)
{
edrk.Status_Ready.bits.Batt = 1;
edrk.to_ing.bits.BLOCK_KEY_OFF = 0;
count_err = 0;
}
if (filter.iqU_1_long >= U_LEVEL_ON_BLOCK_KEY || filter.iqU_2_long >= U_LEVEL_ON_BLOCK_KEY)
{
edrk.Status_Ready.bits.Batt = 1;
edrk.to_ing.bits.BLOCK_KEY_OFF = 0;
count_err = 0;
}
if (filter.iqU_1_long <= U_LEVEL_OFF_BLOCK_KEY && filter.iqU_2_long <= U_LEVEL_OFF_BLOCK_KEY && edrk.SumSbor==0)
{
if (pause_detect_error(&count_err,TIME_WAIT_OFF_BLOCK_KEY,1))
{
edrk.to_ing.bits.BLOCK_KEY_OFF = 1;
edrk.Status_Ready.bits.Batt = 0;
}
}
else
count_err = 0;
}
///////////////////////////////////////////////