/** * @brief Sets the RTC Date(DD/MM/YYYY) * @param DD,MM,YYYY * @retval : None */ void set_time(rtc_t *time) { /*Check if the date entered by the user is correct or not, Displays an error message if date is incorrect */ if((( time->Month == 4 || time->Month == 6 || time->Month == 9 || time->Month == 11) && time->mDay == 31) || (time->Month == 2 && (time->mDay > 29)) || (time->Month == 2 && time->mDay == 29 && (CheckLeap(time->Year)==0))) { DEBUGF("INCORRECT DATE...\n"); } else { s_DateStructVar.Year = time->Year; s_DateStructVar.Month = time->Month; s_DateStructVar.mDay = time->mDay; s_DateStructVar.wDay = WeekDay(time->Year, time->Month, time->mDay); s_DateStructVar.Hour = time->Hour; s_DateStructVar.Minute = time->Minute; s_DateStructVar.Second = time->Second; WRITE_BKP_CLOCK_YEAR(time->Year); WRITE_BKP_CLOCK_MONTH(time->Month); WRITE_BKP_CLOCK_MDAY(time->mDay); WRITE_BKP_CLOCK_WDAY(s_DateStructVar.wDay); WRITE_BKP_CLOCK_TIME( (time->Hour * 60 + time->Minute) * 60 + time->Second); SummerTimeCorrection(); } }
void XTime::GetTime(XString8 &strTime) { int v=GetDayOfWeek(); strTime=WeekDay(v); v=GetDay(); if(v<10) strTime+=",0"; else strTime+=","; strTime+=v; strTime+=' '; //v=GetMonth(); strTime+=Month(GetMonth()); strTime+=' '; strTime+=GetYear(); strTime+=' '; if (this->GetHour()<10) strTime+='0'; strTime+=GetHour(); strTime+=':'; if (this->GetMinute()<10) strTime+='0'; strTime+=GetMinute(); strTime+=':'; if (this->GetSecond()<10) strTime+='0'; strTime+=GetSecond(); strTime+=" GMT"; }
/** * @brief Displays the Date(DD/MM/YY and DAY ) on LCD * @param None * @retval :None */ void DisplayDate(void) { s_DateStructVar.Year=(BKP_ReadBackupRegister(BKP_DR4)); s_DateStructVar.Month=(BKP_ReadBackupRegister(BKP_DR2)); s_DateStructVar.Day=(BKP_ReadBackupRegister(BKP_DR3)); LCD_DisplayChar(Line5,Column5,(s_DateStructVar.Day/10) + 0x30); LCD_DisplayChar(Line5,Column6,(s_DateStructVar.Day%10) + 0x30); LCD_DisplayString(Line5,Column8,MonthsNames[s_DateStructVar.Month-1]); LCD_DisplayChar(Line5,Column12,((s_DateStructVar.Year/1000) + 0x30)); LCD_DisplayChar(Line5,Column13,((s_DateStructVar.Year/100)%10) + 0x30); LCD_DisplayChar(Line5,Column14,((s_DateStructVar.Year/10)%10) + 0x30); LCD_DisplayChar(Line5,Column15,(s_DateStructVar.Year%10) + 0x30); switch(WeekDay(s_DateStructVar.Year,s_DateStructVar.Month,s_DateStructVar.Day)) { case 0: LCD_DisplayString(Line6,Column8,"Sun"); break; case 1: LCD_DisplayString(Line6,Column8,"Mon"); break; case 2: LCD_DisplayString(Line6,Column8,"Tue"); break; case 3: LCD_DisplayString(Line6,Column8,"Wed"); break; case 4: LCD_DisplayString(Line6,Column8,"Thu"); break; case 5: LCD_DisplayString(Line6,Column8,"Fri"); break; case 6: LCD_DisplayString(Line6,Column8,"Sat"); break; } }
// Ñ¡ÖÐijһÌ죬·µ»ØÑ¡ÖÐijÌìµÄË÷ÒýºÅ WORD SelectDay(HWND hDlg, POINT *pt) { RECT rect; GetClientRect(hDlg, &rect); ScreenToClient(hDlg, pt); LONG iRow = (pt->y - rect.top - TITLE_HEIGHT - CAL_TOPGAP) / ROW_HEIGHT; LONG iCol = 7 * (pt->x - rect.left - CAL_LEFTGAP) / CAL_WIDTH + 1; WORD startcol, endrow, endcol; startcol = WeekDay(m_iYear, m_iMonth, 1); endcol = WeekDay(m_iYear, m_iMonth, MonthDays(m_iYear, m_iMonth)); endrow = (MonthDays(m_iYear, m_iMonth) + startcol - 1) / 7; if ((iRow == 0 && iCol<startcol) || (iRow == endrow && iCol>endcol) || iRow > endrow || iCol > 7) { return 0; } return (WORD)(iRow * 7 + iCol + 1 - startcol); }
// »æÖÆÈÕÆÚ void PaintDate(HWND hDlg) { RECT rect; HDC hDC, hSysDC; WORD day = 1; PAINTSTRUCT ps; TEXTMETRIC tm; LOGFONT lf; HFONT hFont; hSysDC = BeginPaint(GetDlgItem(hDlg, IDC_EDIT1), &ps); GetTextMetrics(hSysDC, &tm); // ÉèÖÃÒ»ÏÂÈÕÆÚÇøÓòµÄ±³¾°É« hDC = GetDC(hDlg); GetClientRect(hDlg, &rect); rect.left += CAL_LEFTGAP; rect.right = rect.left + CAL_WIDTH; rect.top += CAL_TOPGAP + TITLE_HEIGHT; rect.bottom = rect.top + ROW_HEIGHT * 6; FillRect(hDC, &rect, CreateSolidBrush(RGB(255, 255, 255))); // ÉèÖÃ×ÖÌå´óС memset(&lf, 0, sizeof(LOGFONT)); lf.lfHeight = tm.tmHeight; lf.lfWidth = 0; hFont = CreateFontIndirect(&lf); SelectObject(hDC, hFont); for (int i=0; i<6; i++, rect.top+=ROW_HEIGHT) // 6ÐÐ { int startx = rect.left + (rect.right-rect.left)/7 - tm.tmHeight; for (int j=1; j<=7; j++, startx+=((rect.right-rect.left)/7)) // 7ÁÐ { if (j<WeekDay(m_iYear,m_iMonth,1) && i==0) // µÚ1ÐÐ continue; if (day > MonthDays(m_iYear,m_iMonth)) break; int border = rect.left + j * (rect.right-rect.left)/7; PaintOneDay(hDC, day, startx, rect.top+1, border); } } EndPaint(hDlg, &ps); DeleteObject(hFont); }
void Data::getWeekDaysReady() { //qDebug() << "weekdaysready"; QDomDocument doc("WeekDays"); if (doc.setContent(this->m_reply2)) { QDomElement root = doc.documentElement(); QDomNode node = root.firstChild(); //qDebug() << "root="<< node.nodeName(); this->m_weekDays.clear(); while (!node.isNull()) { QDomElement e = node.toElement(); if ((!e.isNull()) && (e.tagName() == "WEEKDAY")) { this->m_weekDays.append( WeekDay(e.attribute("id").toInt(), e.attribute("name"), e.attribute("shortName"))); //qDebug() << e.attribute("shortName"); } node = node.nextSibling(); } } emit this->weekDaysReady(); }
/** * @brief Summer Time Correction routine * @param None * @retval : None */ void SummerTimeCorrection(void) { uint8_t CorrectionPending = 0; uint8_t CheckCorrect = 0; if((SummerTimeCorrect & OCTOBER_FLAG_SET) != 0) { if((s_DateStructVar.Month==10) && (s_DateStructVar.mDay >24 )) { for(CheckCorrect = 25; CheckCorrect <=s_DateStructVar.mDay; CheckCorrect++){ if(WeekDay(s_DateStructVar.Year, s_DateStructVar.Month, CheckCorrect )==0) { if(CheckCorrect == s_DateStructVar.mDay){ /* Check if Time is greater than equal to 1:59:59 */ if(get_sec_counter() >= 7199){ CorrectionPending = 1; } }else{ CorrectionPending = 1; } break; } } }else if((s_DateStructVar.Month > 10)) { CorrectionPending = 1; }else if(s_DateStructVar.Month < 3) { CorrectionPending = 1; }else if(s_DateStructVar.Month == 3){ if(s_DateStructVar.mDay < 24) { CorrectionPending = 1; }else{ for(CheckCorrect = 24; CheckCorrect <= s_DateStructVar.mDay;CheckCorrect++){ if(WeekDay(s_DateStructVar.Year, s_DateStructVar.Month, CheckCorrect) == 0){ if(CheckCorrect == s_DateStructVar.mDay){ /*Check if Time is less than 1:59:59 and year is not the same in which March correction was done */ if((get_sec_counter() < 7199) && ((SummerTimeCorrect & 0x3FFF) != s_DateStructVar.Year)){ CorrectionPending = 1; }else{ CorrectionPending = 0; } break; }else{ CorrectionPending = 1; } } } } } }else if((SummerTimeCorrect & MARCH_FLAG_SET) != 0){ if((s_DateStructVar.Month == 3) && (s_DateStructVar.mDay > 24 )) { for(CheckCorrect = 25; CheckCorrect <= s_DateStructVar.mDay; CheckCorrect++){ if(WeekDay(s_DateStructVar.Year, s_DateStructVar.Month, CheckCorrect ) == 0){ if(CheckCorrect == s_DateStructVar.mDay){ /*Check if time is greater than equal to 1:59:59 */ if(get_sec_counter() >= 7199){ CorrectionPending = 1; } }else{ CorrectionPending = 1; } break; } } }else if((s_DateStructVar.Month > 3) && (s_DateStructVar.Month < 10 )){ CorrectionPending=1; }else if(s_DateStructVar.Month == 10){ if(s_DateStructVar.mDay < 24){ CorrectionPending = 1; }else { for(CheckCorrect=24; CheckCorrect <= s_DateStructVar.mDay; CheckCorrect++){ if(WeekDay(s_DateStructVar.Year, s_DateStructVar.Month, CheckCorrect) == 0){ if(CheckCorrect == s_DateStructVar.mDay){ /*Check if Time is less than 1:59:59 and year is not the same in which March correction was done */ if((get_sec_counter() < 7199) && ((SummerTimeCorrect & 0x3FFF) != s_DateStructVar.Year)){ CorrectionPending = 1; }else{ CorrectionPending = 0; } break; } } } } } } if(CorrectionPending == 1) { if((SummerTimeCorrect & OCTOBER_FLAG_SET) != 0) { /* Subtract 1 hour from the current time */ set_sec_counter( get_sec_counter() - 3599); /* Reset October correction flag */ SummerTimeCorrect &= 0xBFFF; /* Set March correction flag */ SummerTimeCorrect |= MARCH_FLAG_SET; SummerTimeCorrect |= s_DateStructVar.Year; WRITE_BKP_SUMMERTIME( SummerTimeCorrect ); }else if((SummerTimeCorrect & MARCH_FLAG_SET)!=0){ /* Add 1 hour to current time */ set_sec_counter( get_sec_counter() + 3601); /* Reset March correction flag */ SummerTimeCorrect &= 0x7FFF; /* Set October correction flag */ SummerTimeCorrect |= OCTOBER_FLAG_SET; SummerTimeCorrect |= s_DateStructVar.Year; WRITE_BKP_SUMMERTIME( SummerTimeCorrect ); } } }
/** * @brief Updates the Date (This function is called when 1 Day has elapsed * @param None * @retval :None */ void DateUpdate(void) { s_DateStructVar.Month = READ_BKP_CLOCK_MONTH(); s_DateStructVar.Year = READ_BKP_CLOCK_YEAR(); s_DateStructVar.mDay = READ_BKP_CLOCK_MDAY(); s_DateStructVar.wDay = READ_BKP_CLOCK_WDAY(); if(s_DateStructVar.Month == 1 || s_DateStructVar.Month == 3 || s_DateStructVar.Month == 5 || s_DateStructVar.Month == 7 || s_DateStructVar.Month == 8 || s_DateStructVar.Month == 10 || s_DateStructVar.Month == 12) { if(s_DateStructVar.mDay < 31) { s_DateStructVar.mDay++; } /* Date structure member: s_DateStructVar.Day = 31 */ else { if(s_DateStructVar.Month != 12) { s_DateStructVar.Month++; s_DateStructVar.mDay = 1; } /* Date structure member: s_DateStructVar.Day = 31 & s_DateStructVar.Month =12 */ else { s_DateStructVar.Month = 1; s_DateStructVar.mDay = 1; s_DateStructVar.Year++; } } } else if(s_DateStructVar.Month == 4 || s_DateStructVar.Month == 6 || s_DateStructVar.Month == 9 ||s_DateStructVar.Month == 11) { if(s_DateStructVar.mDay < 30) { s_DateStructVar.mDay++; } /* Date structure member: s_DateStructVar.Day = 30 */ else { s_DateStructVar.Month++; s_DateStructVar.mDay = 1; } } else if(s_DateStructVar.Month == 2) { if(s_DateStructVar.mDay < 28) { s_DateStructVar.mDay++; } else if(s_DateStructVar.mDay == 28) { /* Leap Year Correction */ if(CheckLeap(s_DateStructVar.Year)) { s_DateStructVar.mDay++; } else { s_DateStructVar.Month++; s_DateStructVar.mDay = 1; } } else if(s_DateStructVar.mDay == 29) { s_DateStructVar.Month++; s_DateStructVar.mDay = 1; } } s_DateStructVar.mDay = WeekDay(s_DateStructVar.Year , s_DateStructVar.Month , s_DateStructVar.mDay); WRITE_BKP_CLOCK_YEAR(s_DateStructVar.Year); WRITE_BKP_CLOCK_MONTH(s_DateStructVar.Month); WRITE_BKP_CLOCK_MDAY(s_DateStructVar.mDay); WRITE_BKP_CLOCK_WDAY(s_DateStructVar.wDay); }
/******************************************************************************* * Function Name : SummerTimeCorrection * Description : Summer Time Correction routine * Input : None * Output : None * Return : None *******************************************************************************/ void SummerTimeCorrection(void) { u8 u8_CorrectionPending=0; u8 u8_CheckCorrect=0; if((u16_SummerTimeCorrect & OCTOBER_FLAG_SET)!=0) { if((s_DateStructVar.u8_Month==10) && (s_DateStructVar.u8_Day >24 )) { for(u8_CheckCorrect = 25;u8_CheckCorrect <=s_DateStructVar.u8_Day;u8_CheckCorrect++) { if(WeekDay(s_DateStructVar.u16_Year,s_DateStructVar.u8_Month,u8_CheckCorrect )==0) { if(u8_CheckCorrect == s_DateStructVar.u8_Day) { /* Check if Time is greater than equal to 1:59:59 */ if(RTC_GetCounter()>=7199) { u8_CorrectionPending=1; } } else { u8_CorrectionPending=1; } break; } } } else if((s_DateStructVar.u8_Month > 10)) { u8_CorrectionPending=1; } else if(s_DateStructVar.u8_Month < 3) { u8_CorrectionPending=1; } else if(s_DateStructVar.u8_Month == 3) { if(s_DateStructVar.u8_Day<24) { u8_CorrectionPending=1; } else { for(u8_CheckCorrect=24;u8_CheckCorrect<=s_DateStructVar.u8_Day;u8_CheckCorrect++) { if(WeekDay(s_DateStructVar.u16_Year,s_DateStructVar.u8_Month,u8_CheckCorrect)==0) { if(u8_CheckCorrect == s_DateStructVar.u8_Day) { /*Check if Time is less than 1:59:59 and year is not the same in which March correction was done */ if((RTC_GetCounter() < 7199) && ((u16_SummerTimeCorrect & 0x3FFF) != \ s_DateStructVar.u16_Year)) { u8_CorrectionPending=1; } else { u8_CorrectionPending=0; } break; } else { u8_CorrectionPending=1; } } } } } } else if((u16_SummerTimeCorrect & MARCH_FLAG_SET)!=0) { if((s_DateStructVar.u8_Month == 3) && (s_DateStructVar.u8_Day >24 )) { for(u8_CheckCorrect = 25;u8_CheckCorrect <=s_DateStructVar.u8_Day;\ u8_CheckCorrect++) { if(WeekDay(s_DateStructVar.u16_Year,s_DateStructVar.u8_Month,\ u8_CheckCorrect )==0) { if(u8_CheckCorrect == s_DateStructVar.u8_Day) { /*Check if time is greater than equal to 1:59:59 */ if(RTC_GetCounter()>=7199) { u8_CorrectionPending=1; } } else { u8_CorrectionPending=1; } break; } } } else if((s_DateStructVar.u8_Month > 3) && (s_DateStructVar.u8_Month < 10 )) { u8_CorrectionPending=1; } else if(s_DateStructVar.u8_Month ==10) { if(s_DateStructVar.u8_Day<24) { u8_CorrectionPending=1; } else { for(u8_CheckCorrect=24;u8_CheckCorrect<=s_DateStructVar.u8_Day;\ u8_CheckCorrect++) { if(WeekDay(s_DateStructVar.u16_Year,s_DateStructVar.u8_Month,\ u8_CheckCorrect)==0) { if(u8_CheckCorrect == s_DateStructVar.u8_Day) { /*Check if Time is less than 1:59:59 and year is not the same in which March correction was done */ if((RTC_GetCounter() < 7199) && \ ((u16_SummerTimeCorrect & 0x3FFF) != s_DateStructVar.u16_Year)) { u8_CorrectionPending=1; } else { u8_CorrectionPending=0; } break; } } } } } } if(u8_CorrectionPending==1) { if((u16_SummerTimeCorrect & OCTOBER_FLAG_SET)!=0) { /* Subtract 1 hour from the current time */ RTC_SetCounter(RTC_GetCounter() - 3599); /* Reset October correction flag */ u16_SummerTimeCorrect &= 0xBFFF; /* Set March correction flag */ u16_SummerTimeCorrect |= MARCH_FLAG_SET; u16_SummerTimeCorrect |= s_DateStructVar.u16_Year; BKP_WriteBackupRegister(BKP_DR7,u16_SummerTimeCorrect); } else if((u16_SummerTimeCorrect & MARCH_FLAG_SET)!=0) { /* Add 1 hour to current time */ RTC_SetCounter(RTC_GetCounter() + 3601); /* Reset March correction flag */ u16_SummerTimeCorrect &= 0x7FFF; /* Set October correction flag */ u16_SummerTimeCorrect |= OCTOBER_FLAG_SET; u16_SummerTimeCorrect |= s_DateStructVar.u16_Year; BKP_WriteBackupRegister(BKP_DR7,u16_SummerTimeCorrect); } } }
/******************************************************************************* * Function Name : RTC_IRQHandler * Description : This function handles RTC global interrupt request. * Input : None * Output : None * Return : None *******************************************************************************/ void RTC_IRQHandler(void) { u8 u8_Month,u8_Day; u16 u16_Year; atcIncrementCounter(); GprsIdleIncMSec(); u8_Month = BKP_ReadBackupRegister(BKP_DR2); u8_Day = BKP_ReadBackupRegister(BKP_DR3); u16_Year = BKP_ReadBackupRegister(BKP_DR4); //NVIC_ClearIRQChannelPendingBit(RTC_IRQn); RTC_ClearITPendingBit(RTC_IT_SEC); /* If counter is equal to 86399: one day was elapsed */ /* This takes care of date change and resetting of counter in case of power on - Run mode/ Main supply switched on condition*/ if(RTC_GetCounter() == 86399) { /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Reset counter value */ RTC_SetCounter(0x0); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Increment the date */ DateUpdate(); } if((RTC_GetCounter()/3600 == 1)&&(((RTC_GetCounter()%3600)/60) == 59)&& (((RTC_GetCounter()%3600)%60) == 59)) { /* March Correction */ if((u8_Month == 3) && (u8_Day >24)) { if(WeekDay(u16_Year,u8_Month,u8_Day)==0) { if((u16_SummerTimeCorrect & 0x8000) == 0x8000) { RTC_SetCounter(RTC_GetCounter() + 3601); /* Reset March correction flag */ u16_SummerTimeCorrect &= 0x7FFF; /* Set October correction flag */ u16_SummerTimeCorrect |= 0x4000; u16_SummerTimeCorrect |= u16_Year; BKP_WriteBackupRegister(BKP_DR7,u16_SummerTimeCorrect); } } } /* October Correction */ if((u8_Month == 10) && (u8_Day >24)) { if(WeekDay(u16_Year,u8_Month,u8_Day)==0) { if((u16_SummerTimeCorrect & 0x4000) == 0x4000) { RTC_SetCounter(RTC_GetCounter() - 3599); /* Reset October correction flag */ u16_SummerTimeCorrect &= 0xBFFF; /* Set March correction flag */ u16_SummerTimeCorrect |= 0x8000; u16_SummerTimeCorrect |= u16_Year; BKP_WriteBackupRegister(BKP_DR7,u16_SummerTimeCorrect); } } } } }