#include "yxbw.h" CYXBW::CYXBW() { m_save = 0; m_load = 0; } CYXBW::~CYXBW() { } void CYXBW::PushYXBW(unionCP56Time& st, int order, BOOLEAN value, BYTE qds, int uid, int point, int type) { m_yxbws[m_save].st.year = st.year; m_yxbws[m_save].st.month = st.month; m_yxbws[m_save].st.dayofmonth = st.dayofmonth; m_yxbws[m_save].st.dayofweek = st.dayofweek; m_yxbws[m_save].st.hour = st.hour; m_yxbws[m_save].st.minute = st.minute; m_yxbws[m_save].st.millisecond = st.millisecond; if (order < 0 || order > DATABASE_YX_NUM) { m_yxbws[m_save].order = -1; } else { m_yxbws[m_save].order = order; } m_yxbws[m_save].value = value; m_yxbws[m_save].uid = uid; m_yxbws[m_save].point = point; m_yxbws[m_save].type = type; m_yxbws[m_save].qds = qds; #if 0 m_yxbws[m_save].bl = ((qds & 0x10) == 0x10); m_yxbws[m_save].sb = ((qds & 0x20) == 0x20); m_yxbws[m_save].nt = ((qds & 0x40) == 0x40); m_yxbws[m_save].iv = ((qds & 0x80) == 0x80); #endif m_save++; m_save = m_save % DATABASE_YXBW_NUM; } void CYXBW::DumpYXBW(void) { FILE* pf; char text[64]; BOOLEAN bNewFile; if (m_load == m_save) return; snprintf(text, sizeof(text), FILE_YXBW_LOG, (int)system32.now.month, (int)system32.now.dayofmonth); 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, "类型(DEV/AUTO);点号;值;单元号;单元类型;单元描述;单元点号;描述\n"); } fseek(pf, 0, SEEK_END); char pathName[512]; FILE* static_unit; struUnitStatic unit; snprintf(pathName, sizeof(pathName), "%s/%s", configpath, FILE_UNIT_STATIC); static_unit = fopen(pathName, "rb"); FILE* static_yx; struYXStatic yx; snprintf(pathName, sizeof(pathName), "%s/%s", configpath, FILE_DATABASE_YX_STATIC); static_yx = fopen(pathName, "rb"); while (m_load != m_save) { memset(&unit, 0, sizeof(unit)); if (static_unit != NULL && fseek(static_unit, sizeof(struUnitStatic)*m_yxbws[m_load].uid, SEEK_SET) == 0) { fread(&unit, sizeof(struUnitStatic), 1, static_unit); unit.name[31] = '\0'; unit.model[15] = '\0'; } memset(&yx, 0, sizeof(yx)); if (static_yx != NULL && fseek(static_yx, sizeof(struYXStatic)*m_yxbws[m_load].order, SEEK_SET) == 0) { fread(&yx, sizeof(struYXStatic), 1, static_yx); yx.name[63] = '\0'; } fprintf(pf, "%s;%d;%s;%d;%s;%s;%d;%s\n", m_yxbws[m_load].type == YXBWT_DEV ? "DEV" : "AUTO", m_yxbws[m_load].order, m_yxbws[m_load].value ? "ON" : "OFF", m_yxbws[m_load].uid, unit.model, unit.name, m_yxbws[m_load].point, yx.name); m_load++; m_load = m_load % DATABASE_YXBW_NUM; } fclose(pf); if (static_unit) fclose(static_unit); if (static_yx) fclose(static_yx); } BOOLEAN CYXBW::GetYXBW(LONG& pos, int& order, BOOLEAN& value, BYTE& qds) { struYXBW* pYXBW; if (pos < 0 || pos >= DATABASE_YXBW_NUM) { pos = 0; } while (pos != m_save) { pYXBW = &m_yxbws[pos]; if (pYXBW->order >= 0 && pYXBW->order < DATABASE_YX_NUM) { break; } pos++; pos = pos % DATABASE_YXBW_NUM; } if (pos == m_save) { return FALSE; } order = pYXBW->order; value = pYXBW->value; qds = pYXBW->qds;//((pYXBW->bl << 4) | (pYXBW->sb << 5) | (pYXBW->nt << 6) | (pYXBW->iv << 7)); return TRUE; } BOOLEAN CYXBW::GetYXBW(LONG& pos, unionCP56Time& st, int& order, BOOLEAN& value, BYTE& qds, int& uid, int& point, int& type) { struYXBW* pYXBW; if (pos < 0 || pos >= DATABASE_YXBW_NUM) { pos = 0; } while (pos != m_save) { pYXBW = &m_yxbws[pos]; if (pYXBW->order >= 0 && pYXBW->order < DATABASE_YX_NUM) { break; } pos++; pos = pos % DATABASE_YXBW_NUM; } if (pos == m_save) { return FALSE; } st.year = pYXBW->st.year; st.month = pYXBW->st.month; st.dayofmonth = pYXBW->st.dayofmonth; st.dayofweek = pYXBW->st.dayofweek; st.hour = pYXBW->st.hour; st.minute = pYXBW->st.minute; st.millisecond = pYXBW->st.millisecond; st.IV = pYXBW->st.IV; st.SU = pYXBW->st.SU; order = pYXBW->order; uid = pYXBW->uid; point = pYXBW->point; type = pYXBW->type; value = pYXBW->value; qds = pYXBW->qds;//((pYXBW->bl << 4) | (pYXBW->sb << 5) | (pYXBW->nt << 6) | (pYXBW->iv << 7)); return TRUE; } BOOLEAN CYXBW::GetYXBW(LONG& pos, unionCP56Time& st, int& order, BOOLEAN& value, BYTE& qds, int& type) { struYXBW* pYXBW; if (pos < 0 || pos >= DATABASE_YXBW_NUM) { pos = 0; } while (pos != m_save) { pYXBW = &m_yxbws[pos]; if (pYXBW->order >= 0 && pYXBW->order < DATABASE_YX_NUM) { break; } pos++; pos = pos % DATABASE_YXBW_NUM; } if (pos == m_save) { return FALSE; } st.year = pYXBW->st.year; st.month = pYXBW->st.month; st.dayofmonth = pYXBW->st.dayofmonth; st.dayofweek = pYXBW->st.dayofweek; st.hour = pYXBW->st.hour; st.minute = pYXBW->st.minute; st.millisecond = pYXBW->st.millisecond; st.IV = pYXBW->st.IV; st.SU = pYXBW->st.SU; order = pYXBW->order; type = pYXBW->type; value = pYXBW->value; qds = pYXBW->qds;//((pYXBW->bl << 4) | (pYXBW->sb << 5) | (pYXBW->nt << 6) | (pYXBW->iv << 7)); return TRUE; } int CYXBW::GetSavePos(void) const { return m_save; }