map/das-dn/comm/ytlog.cpp

131 lines
3.9 KiB
C++
Raw Permalink Normal View History

2024-07-08 10:27:17 +08:00
#include "ytlog.h"
CYTLog::CYTLog()
{
m_save = 0;
m_load = 0;
}
CYTLog::~CYTLog()
{
}
void CYTLog::PushYTLog(unionCP56Time& st, int point, DWORD value, BYTE type, BYTE source, int uid)
{
m_ytlogs[m_save].st.year = st.year;
m_ytlogs[m_save].st.month = st.month;
m_ytlogs[m_save].st.dayofmonth = st.dayofmonth;
m_ytlogs[m_save].st.dayofweek = st.dayofweek;
m_ytlogs[m_save].st.hour = st.hour;
m_ytlogs[m_save].st.minute = st.minute;
m_ytlogs[m_save].st.millisecond = st.millisecond;
if (point < 0 || point > DATABASE_YT_NUM)
{
m_ytlogs[m_save].point = -1;
}
else
{
m_ytlogs[m_save].point = point;
}
m_ytlogs[m_save].value = value;
m_ytlogs[m_save].type = type;
m_ytlogs[m_save].source = source;
m_ytlogs[m_save].uid = uid;
m_save++;
m_save = m_save % DATABASE_YT_LOG_NUM;
}
void CYTLog::DumpYTLog(void)
{
FILE* pf;
BOOLEAN bNewFile;
char text[64];
char type[8];
char src[8];
if (m_load == m_save) return;
snprintf(text, sizeof(text), FILE_YT_LOG, (int)system32.now.month, (int)system32.now.dayofmonth);
bNewFile = FALSE;
pf = fopen(text, "rb+");
if (pf == NULL)
{
pf = fopen(text, "wb+");
bNewFile = TRUE;
}
if (pf == NULL) return;
if (bNewFile)
{
fseek(pf, 0, SEEK_SET);
fprintf(pf, "时间;点号;命令;类型;触发源;单元号;单元类型;单元描述\n");
}
fseek(pf, 0, SEEK_END);
//打开Unit.sta静态文件
char pathName[512];
FILE* static_unit;
struUnitStatic unit;
snprintf(pathName, sizeof(pathName), "%s/%s", configpath, FILE_UNIT_STATIC);
static_unit = fopen(pathName, "rb");
while (m_load != m_save)
{
memset(type, 0, sizeof(type));
memset(src, 0, sizeof(src));
if (m_ytlogs[m_load].type == YTT_SELREQ)
{
snprintf(type, sizeof(type), "%s", "SELREQ");
}
else if (m_ytlogs[m_load].type == YTT_SELOUT)
{
snprintf(type, sizeof(type), "%s", "SELOUT");
}
else if (m_ytlogs[m_load].type == YTT_SELRET)
{
snprintf(type, sizeof(type), "%s", "SELRET");
}
else if (m_ytlogs[m_load].type == YTT_ABRREQ)
{
snprintf(type, sizeof(type), "%s", "ABRREQ");
}
else if (m_ytlogs[m_load].type == YTT_EXEREQ)
{
snprintf(type, sizeof(type), "%s", "EXEREQ");
}
else if (m_ytlogs[m_load].type == YTT_EXEOUT)
{
snprintf(type, sizeof(type), "%s", "EXEOUT");
}
if (m_ytlogs[m_load].source == YTS_AUTO)
{
snprintf(src, sizeof(src), "%s", "AUTO");
}
else if (m_ytlogs[m_load].source == YTS_MANU)
{
snprintf(src, sizeof(src), "%s", "MANU");
}
else if (m_ytlogs[m_load].source == YTS_PROC)
{
snprintf(src, sizeof(src), "%s", "PROC");
}
memset(&unit, 0, sizeof(unit));
if (static_unit != NULL && fseek(static_unit, sizeof(struUnitStatic)*m_ytlogs[m_load].uid, SEEK_SET) == 0)
{
fread(&unit, sizeof(struUnitStatic), 1, static_unit);
unit.name[31] = '\0';
unit.model[15] = '\0';
}
fprintf(pf, "%04d/%02d/%02d %02d:%02d:%02d.%03d;%d;%d;%s;%s;%d;%s;%s\n",
m_ytlogs[m_load].st.year + 2000, m_ytlogs[m_load].st.month, m_ytlogs[m_load].st.dayofmonth,
m_ytlogs[m_load].st.hour, m_ytlogs[m_load].st.minute, m_ytlogs[m_load].st.millisecond / 1000, m_ytlogs[m_load].st.millisecond % 1000,
m_ytlogs[m_load].point,
m_ytlogs[m_load].value,
type,
src,
m_ytlogs[m_load].uid, unit.model, unit.name);
m_load++;
m_load = m_load % DATABASE_YT_LOG_NUM;
}
fclose(pf);
if (static_unit) fclose(static_unit);
}