matlab_23550/Inu/Src2/main/alarm_log.c

197 lines
5.0 KiB
C

/*
* alarm_log.c
*
* Created on: 11 ñåíò. 2024 ã.
* Author: yura
*/
#include "edrk_main.h"
#include "alarm_log_can.h"
#include "alarm_log.h"
#include "log_params.h"
#include "logs_hmi.h"
#include "global_time.h"
#define PAUSE_AUTO_SAVE_ALARM_LOG_SECONDS 20 // 20 sec
#define PAUSE_AUTO_STOP_ALARM_LOG_SECONDS 5 // 5 sec
void send_alarm_log_pult(void)
{
static int prev_imit_send_alarm_log_pult = 0;
int to_store = 0;
static int flag_wait_alarm = 0, prev_Ready2 = 0, flag_store_log = 0, flag_store_log_prepare = 0, flag_auto_logs = 0, flag_stop_alarm = 0;
static unsigned int pause_store_logs = 0, pause_stop_logs = 0;
// èìèòàöèÿ ñ òåðìèíàëêè
if (edrk.imit_send_alarm_log_pult && prev_imit_send_alarm_log_pult == 0)
flag_store_log = 1;
prev_imit_send_alarm_log_pult = edrk.imit_send_alarm_log_pult;
// àâòî ëîããèðîâàíèå àâàðèéíûõ ëîãîâ íà ïóëüò
// ñõåìà ñîáðàëàñü? çíà÷èò ëîâèì àâàðèþ
if (prev_Ready2==0 && edrk.Status_Ready.bits.ready_final)
{
flag_wait_alarm = 1;
flag_stop_alarm = 0;
}
if (prev_Ready2==1 && edrk.Status_Ready.bits.ready_final==0)
{
// äàåì ïàóçó, æäåì îøèáêè
init_timer_sec(&pause_stop_logs);
flag_stop_alarm = 1;
}
prev_Ready2 = edrk.Status_Ready.bits.ready_final;
//ñõåìà áûëà ñîáðàíà è ïîÿâèëàñü àâàðèÿ
if (flag_wait_alarm && edrk.summ_errors)
{
// ìîæíî ñîõðàíèòüñÿ
flag_store_log_prepare = 1;
flag_wait_alarm = 0;
flag_stop_alarm = 0;
init_timer_sec(&pause_store_logs);
}
// //ñõåìà áûëà ðàçîáðàíà, íî îøèáîê ìîæåò è íå áûòü
// if (flag_stop_alarm)
// {
//
//
// }
// îøèáîê íå ïîÿâèëîñü, ïðåêðàùàåì æäàòü
if (flag_stop_alarm && detect_pause_sec(PAUSE_AUTO_STOP_ALARM_LOG_SECONDS, &pause_stop_logs))
{
flag_stop_alarm = 0;
flag_wait_alarm = 0;
}
if (flag_store_log_prepare)
{
flag_auto_logs = detect_pause_sec(PAUSE_AUTO_SAVE_ALARM_LOG_SECONDS, &pause_store_logs);
}
if (flag_auto_logs)
{
flag_store_log_prepare = 0;
flag_auto_logs = 0;
// ñîõðàíÿåì
flag_store_log = 1;
flag_wait_alarm = 0;
flag_stop_alarm = 0;
}
// ïðîèçâîäèì ñáðîñ ëîãîâ íà ïóëüò
if (flag_store_log)
{
if (edrk.pult_cmd.log_what_memory >= 2)
to_store = 2;
else
if (edrk.pult_cmd.log_what_memory >= 1)
to_store = 1;
else
to_store = 0;
log_to_HMI.sdusb = to_store;
// åñëè åñòü íîñèòåëè òî ñîõðàíÿåì
if (log_to_HMI.sdusb)
{
log_to_HMI.send_log = 3;
}
flag_store_log = 0;
}
}
void test_send_alarm_log(int alarm_cmd)
{
static unsigned int points_alarm_log = 1000;
// static unsigned int nchannel_alarm_log = 30;
static int prev_alarm_cmd = 0;
static int local_alarm_cmd = 0;
if (alarm_cmd && prev_alarm_cmd==0 && alarm_log_can.stage==0)
{
// i_led2_on();
alarm_log_can.post_points = COUNT_SAVE_LOG_OFF;//100; // êîëè÷åñòâî ïîñòàâàðèéíûéõ çàïèñåé
alarm_log_can.oscills = log_params.BlockSizeErr;//nchannel_alarm_log; // êîëè÷åñòâî êîëîíîê
alarm_log_can.global_enable = 1;
alarm_log_can.start_adr_temp = (int *)0xc0000; // àäðåñ äëÿ âðåìåííîãî ðàçìåùåíèÿ êîïèè ëîãà, ëîã ñêîïèðóåòñÿ èç öèêëè÷åñêîãî áóôåðà â ýòîò ðàçâåðíóâøèñü.
// alarm_log_can.finish_adr_temp = (int *)0xa0000; // àäðåñ äëÿ âðåìåííîãî ðàçìåùåíèÿ êîïèè ëîãà, ëîã ñêîïèðóåòñÿ èç öèêëè÷åñêîãî áóôåðà â ýòîò ðàçâåðíóâøèñü.
alarm_log_can.start_adr_real_logs = (int *)log_params.start_address_log;//(int *)START_ADDRESS_LOG; // àäðåñ íà÷àëà ðåàëüíûõ ëîãîâ â öèêëè÷åñêîì áóôåðå
alarm_log_can.finish_adr_real_log = (int *)log_params.end_address_log;//(int *)logpar.; // êîíåö ëîãîâ â öèêëè÷åñêîì áóôåðå
alarm_log_can.current_adr_real_log = (int *)log_params.addres_mem;
alarm_log_can.temp_points = points_alarm_log; // ðåàëüíûé ðàçìåð öèêëè÷åñêãî áóôåðà â òî÷êàõ.
// alarm_log_can.real_points = 1000; // íóæíûé êóñîê äëÿ êîïèè, äàííîå êîëè÷åñòâî ñêîïèðóåòñÿ èç öèêëè÷åñêîãî áóôåðà âî âðåìåííûé ëîã.
alarm_log_can.step = 450; // mks
local_alarm_cmd = alarm_cmd;
// alarm_log_can.status_alarm = alarm_cmd;//cmd_alarm_log; // êîä àâàðèè
alarm_log_can.start = 0x1;
alarm_log_can.stop = 0x1;
alarm_log_can.copy2temp = 0x1;
alarm_log_can.clear(&alarm_log_can);
// alarm_log_can.send(&alarm_log_can);
// i_led2_off();
}
else
local_alarm_cmd = 0;
alarm_log_can.status_alarm = local_alarm_cmd;//cmd_alarm_log; // êîä àâàðèè
alarm_log_can.send(&alarm_log_can);
if (alarm_log_can.stage)
{
// i_led2_on_off(1);
}
else
{
// i_led2_on_off(0);
}
prev_alarm_cmd = alarm_cmd;
}
////////////////////////////////////////////////////////////