unsigned int ComputeDayOfYear(unsigned short year, unsigned short mon, unsigned short day )
{
return ((mon * 275 / 9) - (((mon + 9) / 12) * (1 + (((year % 4) + 2) / 3))) + day - 30);
}
void conv_dnp_to_gmt(unsigned char *buf, unsigned short *pSysTime)
{
unsigned int lsg, msg, lval;
unsigned short year=0,mon=0,day=0,hour=0,min=0,sec=0,msec=0;
lsg = buf[0] | (buf[1] << 8);
msg = buf[4] | (buf[5] << 8);
msg = (msg << 16) & 0xffff0000;
msg += buf[2] | (buf[3] << 8);
lval = (msg%60000) << 16;
msg = ((msg/60000) << 16) + ((lval + lsg) / 60000);
lsg = (lval + lsg) % 60000;
msec = (lsg % 1000) & 0xffff;
sec = (lsg / 1000) & 0xff;
min = (msg % 60) & 0xff;
msg = msg / 60; /* now holds hours */
hour = (msg % 24) & 0xff;
msg = msg / 24; /* now holds days */
year = ((msg / 365) + 1970) & 0xffff;
while( 1 ){
lval = ((((unsigned int) year) - 1970) * 365) +
((((unsigned int) year) - 1969) / 4);
if( lval > msg )
year--;
else
break; /* no more year adjustment is necessary; we guessed correctly */
}
msg = msg - lval + 1; /* now contains days */
/* since Jan 1. */
mon = (msg/28 + 1) & 0xff;
day = (msg%28 + 1) & 0xff;
while( ComputeDayOfYear(year, mon, day) != msg )
{
if( --day == 0 )
{ mon--;
day = 31;
}
}
pSysTime[6] = msec;
pSysTime[5] = sec;
pSysTime[4] = min;
pSysTime[3] = hour;
pSysTime[2] = day;
pSysTime[1] = mon;
pSysTime[0] = year;
}
void conv_gmt_to_dnp(unsigned char *buf, unsigned short *pSysTime)
{
unsigned char w_lsg[2];
unsigned char w_msg[4];
unsigned short year=0,mon=0,day=0,hour=0,min=0,sec=0,msec=0;
unsigned int msg=0,lsg=0;
year = pSysTime[0];
mon = pSysTime[1];
day = pSysTime[2];
hour = pSysTime[3];
min = pSysTime[4];
sec = pSysTime[5];
msec = pSysTime[6];
msg = ((year-1970) * 365) + ((year-1969)/4);
msg += ComputeDayOfYear(year, mon, day) - 1;
msg = (msg * 24) + hour;
msg = (msg * 60) + min;
lsg = sec * 1000 + msec;
lsg += (msg & 0xffff) * 60000;
msg = ((msg >> 16)* 60000) + (lsg >> 16);
w_lsg[0] = lsg & 0xff;
w_lsg[1] = (lsg >> 8) & 0xff;
memcpy(&buf[0], &w_lsg, 2);
w_msg[0] = msg & 0xff;
w_msg[1] = (msg>>8) & 0xff;
w_msg[2] = (msg>>16) & 0xff;
w_msg[3] = (msg>>24) & 0xff;
memcpy(&buf[2], &w_msg, 4);
}
'기타' 카테고리의 다른 글
HP ZBook x2 시스템 복구 방법, CMOS 모드 들어가기 (0) | 2022.04.15 |
---|---|
재부팅 없이 비트락 잠금 상태 변경 (0) | 2022.04.01 |
MSVS 팀프로젝트 소스 다운로드 방법 (0) | 2016.09.20 |
Windows 7 에서 프로그램 아이콘이 표시되지 않는 문제 해결 방법 (0) | 2016.08.24 |
베가아이언 투명 젤리 케이스 (342) | 2015.01.28 |