⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timeclass.cpp

📁 高速公路收费系统车道软件. 功能: 1 检测公路过往车辆 2 收费过程控制和数据采集 3 车辆信息和图片上传服务器.
💻 CPP
字号:
// TimeClass.cpp: implementation of the CTimeInfo class.
//
//////////////////////////////////////////////////////////////////////
 
#include "stdafx.h"
#include "lane_new.h"
#include "TimeClass.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

extern CLane_newApp theApp;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
UINT CTimeInfo::nNowYear=0;
UINT CTimeInfo::nNowMonth=0;
UINT CTimeInfo::nNowDay=0;
UINT CTimeInfo::nNowDayCount=0;
UINT CTimeInfo::nNowHour=0;
UINT CTimeInfo::nNowMinute=0;
UINT CTimeInfo::nNowSecond=0;
ULONG CTimeInfo::nUnixTime;

//	当前时间值初始化
CTimeInfo::CTimeInfo()
{
}

//	通过读取系统时钟获取当前时间
void CTimeInfo::SetTime()
{
	time_t loc;
	struct tm *NowTime;
	theApp.muxTime.Lock();
	time(&loc);
	NowTime=localtime(&loc);
	theApp.muxTime.Unlock();
	if(NowTime==NULL) return;
	nUnixTime=(ULONG)loc;
	nNowYear=NowTime->tm_year+1900;
	nNowMonth=NowTime->tm_mon+1;
	nNowDay=NowTime->tm_mday;
	nNowDayCount=NowTime->tm_yday+1;
	nNowHour=NowTime->tm_hour;
	nNowMinute=NowTime->tm_min;
	nNowSecond=NowTime->tm_sec;
	CScreen m_clsScreen;
	m_clsScreen.DrawTimeWindow();
	SendMessage(theApp.m_pMainWnd->m_hWnd,WM_STARTUP_TIMER,SECOND_TIMER,0);
}

//	获取当前年
UINT CTimeInfo::GetYear()
{
	return nNowYear;
}

//	获取当前月
UINT CTimeInfo::GetMonth()
{
	return nNowMonth;
}

//	获取当前日
UINT CTimeInfo::GetDay()
{
	return nNowDay;
}

//	获取当前天数
UINT CTimeInfo::GetDayCount()
{
	return nNowDayCount;
}

//	获取当前时
UINT CTimeInfo::GetHour()
{
	return nNowHour;
}

//	获取当前分
UINT CTimeInfo::GetMinute()
{
	return nNowMinute;
}

//	获取当前秒
UINT CTimeInfo::GetSecond()
{
	return nNowSecond;
}

//	获取UNIX时间
ULONG CTimeInfo::GetUnixTime()
{
	return nUnixTime;
}

//	按上位机的命令更改车道时间。对时消息有两种格式,一种精确到秒,
//	另一种精确到分;对时消息中的年只有2位,需要扩展到4位;如果上
//	位机的时间和本机的时间变化不大,本机时间不做改动,否则更改本
//	机系统时间。由于系统时间更改后各个定时器的起始时间不再准确,
//	因此必须重新启动各个定时器

//	对时消息数据格式:'1',日(2 byte) 月(2 byte) 年(2 byte)
//	时(2 byte) 分(2 byte) 监控模式(1 byte,未用) 秒(2 byte)
void CTimeInfo::AdjustTime(unsigned char *ReceiveData)
{
	char tmpStr[5];
	memset(tmpStr,0,5);
	memmove(tmpStr,ReceiveData,2);
	int nDay=atoi(tmpStr);
	memset(tmpStr,0,5);
	memmove(tmpStr,ReceiveData+2,2);
	int nMonth=atoi(tmpStr);
	memset(tmpStr,0,5);
	memmove(tmpStr,ReceiveData+4,2);
	int nYear=atoi(tmpStr);
	if(nYear>=80){			//时间在20世纪
		nYear+=1900;
	} else {				//时间在21世纪
		nYear+=2000;
	}
	memset(tmpStr,0,5);
	memmove(tmpStr,ReceiveData+6,2);
	int nHour=atoi(tmpStr);
	memset(tmpStr,0,5);
	memmove(tmpStr,ReceiveData+8,2);
	int nMinute=atoi(tmpStr);
//	跳过监控位
	memset(tmpStr,0,5);
	memmove(tmpStr,ReceiveData+11,2);
	int nSecond=atoi(tmpStr);
	if((nYear==(int)nNowYear)&&(nMonth==(int)nNowMonth)
		&&(nDay==(int)nNowDay)&&(nHour==(int)nNowHour)
		&&(nMinute==(int)nNowMinute)) return;
	struct _SYSTEMTIME NowTime;
	NowTime.wYear=nYear;
	NowTime.wMonth=nMonth;
	NowTime.wDay=nDay;
	NowTime.wHour=nHour;
	NowTime.wMinute=nMinute;
	NowTime.wSecond=nSecond;
	NowTime.wMilliseconds=0;
	NowTime.wDayOfWeek=0;
	theApp.muxTime.Lock();
	SetLocalTime(&NowTime);
	theApp.muxTime.Unlock();
	SendMessage(theApp.m_pMainWnd->m_hWnd,WM_STARTUP_TIMER,ALL_TIMER,0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -