int PlMdbInit(void) { sysclock_t clock; dbtime_t dbtime; int rtn; FlagDaySaved = FlagMonthSaved = 1; FlagImpSaved = 1; memset(PlMdbDay, PLDATA_EMPTY, sizeof(PlMdbDay)); memset(PlMdbMonth, PLDATA_EMPTY, sizeof(PlMdbMonth)); memset(PlMdbImp, PLDATA_EMPTY, sizeof(PlMdbImp)); PlMdbLockId = RegisterSysLock(); SysClockRead(&clock); SYSCLOCK_DBTIME(&clock, dbtime);//根据冻结时间得到冻结文件 rtn = ReadPlMdbDay(PlMdbDay, dbtime); if(rtn > 0) DebugPrint(0, "load %d mets plmdb day data\n", rtn); //rtn = ReadPlMdbMonth(PlMdbMonth, dbtime); //if(rtn > 0) DebugPrint(0, "load %d mets plmdb month data\n", rtn); //rtn = ReadPlMdbImp(PlMdbImp, dbtime); //if(rtn > 0) DebugPrint(0, "load plmdb imp ok\n"); SET_INIT_FLAG(PlMdbInit); return 0; }
static void LoadPltData(void) { char filename[64]; sysclock_t clock; int len, itemlen, i, maxprd; plt_filedata_t *pcache; unsigned char *pbuf; ResetPltData(); SysClockRead(&clock); sprintf(filename, "%sdaytest@%02d%02d%02d.db", PLT_FILEPATH, clock.year, clock.month, clock.day); SYSCLOCK_DBTIME(&clock, PltFileDate); PltFileDate.s.tick = 0; len = ReadBinFileCache(filename, MAGIC_FILE_PLT, PltFileCache, sizeof(PltFileCache)); if(len < 4) return; pcache = (plt_filedata_t *)PltFileCache; if(pcache->max_prd == 0 || pcache->max_prd > MAX_FILE_PRD) return; if(pcache->max_met == 0 || pcache->max_met > MAX_PLCMET) return; itemlen = (int)pcache->max_met&0xffff; itemlen = itemlen*MET_DATA_LEN+PRD_HEAD_LEN; maxprd = (int)pcache->max_prd&0xff; i = maxprd*itemlen+FILE_HEAD_LEN; if(len != i) { ErrorLog("invalid file len(%d, %d)\n", len, i); return; } PltFileData.invaid_prd = pcache->invaid_prd; pbuf = (unsigned char *)pcache->prd; for(i=0; i<maxprd; i++) { memcpy(&PltFileData.prd[i], pbuf, itemlen); pbuf += itemlen; } }
/** * @brief 读取外部时钟 * @param clock 返回时钟变量指针 * @return 返回0表示成功, 否则失败 */ int ReadExternSysClock(sysclock_t *clock) { SysClockRead(clock); return 0; }
/** * @brief 得到当前系统时间 * 这个函数返回定时器任务定时更新的当前时间缓存值, 因此要远快于SysClockRead() * @param pclock 储存时间的变量指针 */ void SysClockReadCurrent(struct sysclock *pclock) { SysClockRead(pclock); }