#include "yklog.h" CYKLog::CYKLog() { m_save = 0; m_load = 0; } CYKLog::~CYKLog() { } void CYKLog::PushYKLog(unionCP56Time& st, int point, BOOLEAN value, BYTE type, BYTE source, int uid) { m_yklogs[m_save].st.year = st.year; m_yklogs[m_save].st.month = st.month; m_yklogs[m_save].st.dayofmonth = st.dayofmonth; m_yklogs[m_save].st.dayofweek = st.dayofweek; m_yklogs[m_save].st.hour = st.hour; m_yklogs[m_save].st.minute = st.minute; m_yklogs[m_save].st.millisecond = st.millisecond; if (point < 0 || point > DATABASE_YK_NUM) { m_yklogs[m_save].point = -1; } else { m_yklogs[m_save].point = point; } m_yklogs[m_save].value = value; m_yklogs[m_save].type = type; m_yklogs[m_save].source = source; m_yklogs[m_save].uid = uid; m_save++; m_save = m_save % DATABASE_YK_LOG_NUM; } BOOLEAN CYKLog::GetYKLog(long& pos, unionCP56Time& st, int& point, BOOLEAN& value, BYTE& type, BYTE& source, int& uid) { struYKLog* pYK; if (pos < 0 || pos >= DATABASE_YK_LOG_NUM) pos = 0; while (pos != m_save) { pYK = &m_yklogs[pos]; if (pYK->point >= 0 && pYK->point < DATABASE_YK_NUM) break; pos++; pos = pos % DATABASE_YK_LOG_NUM; } if (pos == m_save) return FALSE; st.year = pYK->st.year; st.month = pYK->st.month; st.dayofmonth = pYK->st.dayofmonth; st.dayofweek = pYK->st.dayofweek; st.hour = pYK->st.hour; st.minute = pYK->st.minute; st.millisecond = pYK->st.millisecond; st.IV = pYK->st.IV; st.SU = pYK->st.SU; point = pYK->point; value = pYK->value; type = pYK->type; source = pYK->source; uid = pYK->uid; return TRUE; } void CYKLog::DumpYKLog(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_YK_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_yklogs[m_load].type == YKT_SELREQ) { snprintf(type, sizeof(type), "%s", "SELREQ"); } else if (m_yklogs[m_load].type == YKT_SELOUT) { snprintf(type, sizeof(type), "%s", "SELOUT"); } else if (m_yklogs[m_load].type == YKT_SELRET) { snprintf(type, sizeof(type), "%s", "SELRET"); } else if (m_yklogs[m_load].type == YKT_ABRREQ) { snprintf(type, sizeof(type), "%s", "ABRREQ"); } else if (m_yklogs[m_load].type == YKT_EXEREQ) { snprintf(type, sizeof(type), "%s", "EXEREQ"); } else if (m_yklogs[m_load].type == YKT_EXEOUT) { snprintf(type, sizeof(type), "%s", "EXEOUT"); } if (m_yklogs[m_load].source == YKS_AUTO) { snprintf(src, sizeof(src), "%s", "AUTO"); } else if (m_yklogs[m_load].source == YKS_MANU) { snprintf(src, sizeof(src), "%s", "MANU"); } else if (m_yklogs[m_load].source == YKS_PROC) { snprintf(src, sizeof(src), "%s", "PROC"); } memset(&unit, 0, sizeof(unit)); if (static_unit != NULL && fseek(static_unit, sizeof(struUnitStatic)*m_yklogs[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;%s;%s;%s;%d;%s;%s\n", m_yklogs[m_load].st.year + 2000, m_yklogs[m_load].st.month, m_yklogs[m_load].st.dayofmonth, m_yklogs[m_load].st.hour, m_yklogs[m_load].st.minute, m_yklogs[m_load].st.millisecond / 1000, m_yklogs[m_load].st.millisecond % 1000, m_yklogs[m_load].point, m_yklogs[m_load].value ? "ON" : "OFF", type, src, m_yklogs[m_load].uid, unit.model, unit.name); m_load++; m_load = m_load % DATABASE_YK_LOG_NUM; } fclose(pf); if (static_unit) fclose(static_unit); }