mirror of
https://github.com/opentx/opentx.git
synced 2025-07-15 20:35:17 +03:00
Replaced all 1900 with TM_YEAR_BASE
This commit is contained in:
parent
6378c97b33
commit
37ea272bd4
15 changed files with 23 additions and 23 deletions
|
@ -388,7 +388,7 @@ int cliSet(const char ** argv)
|
||||||
struct gtm t;
|
struct gtm t;
|
||||||
int year, month, day, hour, minute, second;
|
int year, month, day, hour, minute, second;
|
||||||
if (toInt(argv, 2, &year) > 0 && toInt(argv, 3, &month) > 0 && toInt(argv, 4, &day) > 0 && toInt(argv, 5, &hour) > 0 && toInt(argv, 6, &minute) > 0 && toInt(argv, 7, &second) > 0) {
|
if (toInt(argv, 2, &year) > 0 && toInt(argv, 3, &month) > 0 && toInt(argv, 4, &day) > 0 && toInt(argv, 5, &hour) > 0 && toInt(argv, 6, &minute) > 0 && toInt(argv, 7, &second) > 0) {
|
||||||
t.tm_year = year-1900;
|
t.tm_year = year-TM_YEAR_BASE;
|
||||||
t.tm_mon = month-1;
|
t.tm_mon = month-1;
|
||||||
t.tm_mday = day;
|
t.tm_mday = day;
|
||||||
t.tm_hour = hour;
|
t.tm_hour = hour;
|
||||||
|
@ -587,7 +587,7 @@ int cliDisplay(const char ** argv)
|
||||||
else if (!strcmp(argv[1], "rtc")) {
|
else if (!strcmp(argv[1], "rtc")) {
|
||||||
struct gtm utm;
|
struct gtm utm;
|
||||||
gettime(&utm);
|
gettime(&utm);
|
||||||
serialPrint("rtc = %4d-%02d-%02d %02d:%02d:%02d.%02d0", utm.tm_year+1900, utm.tm_mon+1, utm.tm_mday, utm.tm_hour, utm.tm_min, utm.tm_sec, g_ms100);
|
serialPrint("rtc = %4d-%02d-%02d %02d:%02d:%02d.%02d0", utm.tm_year+TM_YEAR_BASE, utm.tm_mon+1, utm.tm_mday, utm.tm_hour, utm.tm_min, utm.tm_sec, g_ms100);
|
||||||
}
|
}
|
||||||
else if (!strcmp(argv[1], "volume")) {
|
else if (!strcmp(argv[1], "volume")) {
|
||||||
serialPrint("volume = %d", getVolume());
|
serialPrint("volume = %d", getVolume());
|
||||||
|
|
|
@ -88,7 +88,7 @@ void dumpTraceBuffer()
|
||||||
struct gtm tp;
|
struct gtm tp;
|
||||||
filltm(&traceBuffer[n].time, &tp);
|
filltm(&traceBuffer[n].time, &tp);
|
||||||
TRACE_NOCRLF("%02d ", n);
|
TRACE_NOCRLF("%02d ", n);
|
||||||
TRACE_NOCRLF("%4d-%02d-%02d,%02d:%02d:%02d.%02d0", tp.tm_year+1900, tp.tm_mon+1, tp.tm_mday, tp.tm_hour, tp.tm_min, tp.tm_sec, traceBuffer[n].time_ms);
|
TRACE_NOCRLF("%4d-%02d-%02d,%02d:%02d:%02d.%02d0", tp.tm_year+TM_YEAR_BASE, tp.tm_mon+1, tp.tm_mday, tp.tm_hour, tp.tm_min, tp.tm_sec, traceBuffer[n].time_ms);
|
||||||
TRACE(" %03d 0x%08x", traceBuffer[n].event, traceBuffer[n].data);
|
TRACE(" %03d 0x%08x", traceBuffer[n].event, traceBuffer[n].data);
|
||||||
if (traceBuffer[n].time == 0 && traceBuffer[n].time_ms == 0) break;
|
if (traceBuffer[n].time == 0 && traceBuffer[n].time_ms == 0) break;
|
||||||
#if !defined(SIMU)
|
#if !defined(SIMU)
|
||||||
|
|
|
@ -163,7 +163,7 @@ void menuRadioSetup(event_t event)
|
||||||
uint8_t rowattr = (menuHorizontalPosition==j ? attr : 0);
|
uint8_t rowattr = (menuHorizontalPosition==j ? attr : 0);
|
||||||
switch (j) {
|
switch (j) {
|
||||||
case 0:
|
case 0:
|
||||||
lcdDrawNumber(RADIO_SETUP_DATE_COLUMN, y, t.tm_year+1900, rowattr|RIGHT);
|
lcdDrawNumber(RADIO_SETUP_DATE_COLUMN, y, t.tm_year+TM_YEAR_BASE, rowattr|RIGHT);
|
||||||
if (rowattr && (s_editMode>0 || p1valdiff)) t.tm_year = checkIncDec(event, t.tm_year, 112, 200, 0);
|
if (rowattr && (s_editMode>0 || p1valdiff)) t.tm_year = checkIncDec(event, t.tm_year, 112, 200, 0);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -172,7 +172,7 @@ void menuRadioSetup(event_t event)
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
int16_t year = 1900 + t.tm_year;
|
int16_t year = TM_YEAR_BASE + t.tm_year;
|
||||||
int8_t dlim = (((((year%4==0) && (year%100!=0)) || (year%400==0)) && (t.tm_mon==1)) ? 1 : 0);
|
int8_t dlim = (((((year%4==0) && (year%100!=0)) || (year%400==0)) && (t.tm_mon==1)) ? 1 : 0);
|
||||||
static const pm_uint8_t dmon[] PROGMEM = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
static const pm_uint8_t dmon[] PROGMEM = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||||
dlim += pgm_read_byte(&dmon[t.tm_mon]);
|
dlim += pgm_read_byte(&dmon[t.tm_mon]);
|
||||||
|
|
|
@ -137,7 +137,7 @@ void menuRadioSetup(event_t event)
|
||||||
uint8_t rowattr = (menuHorizontalPosition==j ? attr : 0);
|
uint8_t rowattr = (menuHorizontalPosition==j ? attr : 0);
|
||||||
switch (j) {
|
switch (j) {
|
||||||
case 0:
|
case 0:
|
||||||
lcdDrawNumber(RADIO_SETUP_DATE_COLUMN, y, t.tm_year+1900, rowattr|RIGHT);
|
lcdDrawNumber(RADIO_SETUP_DATE_COLUMN, y, t.tm_year+TM_YEAR_BASE, rowattr|RIGHT);
|
||||||
if (rowattr && s_editMode>0) t.tm_year = checkIncDec(event, t.tm_year, 112, 200, 0);
|
if (rowattr && s_editMode>0) t.tm_year = checkIncDec(event, t.tm_year, 112, 200, 0);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -146,7 +146,7 @@ void menuRadioSetup(event_t event)
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
int16_t year = 1900 + t.tm_year;
|
int16_t year = TM_YEAR_BASE + t.tm_year;
|
||||||
int8_t dlim = (((((year%4==0) && (year%100!=0)) || (year%400==0)) && (t.tm_mon==1)) ? 1 : 0);
|
int8_t dlim = (((((year%4==0) && (year%100!=0)) || (year%400==0)) && (t.tm_mon==1)) ? 1 : 0);
|
||||||
static const pm_uint8_t dmon[] PROGMEM = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
static const pm_uint8_t dmon[] PROGMEM = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||||
dlim += pgm_read_byte(&dmon[t.tm_mon]);
|
dlim += pgm_read_byte(&dmon[t.tm_mon]);
|
||||||
|
|
|
@ -143,7 +143,7 @@ bool menuRadioSetup(event_t event)
|
||||||
uint8_t rowattr = (menuHorizontalPosition==j ? attr : 0);
|
uint8_t rowattr = (menuHorizontalPosition==j ? attr : 0);
|
||||||
switch (j) {
|
switch (j) {
|
||||||
case 0:
|
case 0:
|
||||||
lcdDrawNumber(RADIO_SETUP_2ND_COLUMN, y, t.tm_year+1900, flags|rowattr);
|
lcdDrawNumber(RADIO_SETUP_2ND_COLUMN, y, t.tm_year+TM_YEAR_BASE, flags|rowattr);
|
||||||
if (rowattr && s_editMode>0) t.tm_year = checkIncDec(event, t.tm_year, 112, 200, 0);
|
if (rowattr && s_editMode>0) t.tm_year = checkIncDec(event, t.tm_year, 112, 200, 0);
|
||||||
lcdDrawText(lcdNextPos+3, y, "-", flags);
|
lcdDrawText(lcdNextPos+3, y, "-", flags);
|
||||||
break;
|
break;
|
||||||
|
@ -154,7 +154,7 @@ bool menuRadioSetup(event_t event)
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
int16_t year = 1900 + t.tm_year;
|
int16_t year = TM_YEAR_BASE + t.tm_year;
|
||||||
int8_t dlim = (((((year%4==0) && (year%100!=0)) || (year%400==0)) && (t.tm_mon==1)) ? 1 : 0);
|
int8_t dlim = (((((year%4==0) && (year%100!=0)) || (year%400==0)) && (t.tm_mon==1)) ? 1 : 0);
|
||||||
static const pm_uint8_t dmon[] PROGMEM = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
static const pm_uint8_t dmon[] PROGMEM = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||||
dlim += pgm_read_byte(&dmon[t.tm_mon]);
|
dlim += pgm_read_byte(&dmon[t.tm_mon]);
|
||||||
|
|
|
@ -236,7 +236,7 @@ void logsWrite()
|
||||||
lastRtcTime = g_rtcTime;
|
lastRtcTime = g_rtcTime;
|
||||||
gettime(&utm);
|
gettime(&utm);
|
||||||
}
|
}
|
||||||
f_printf(&g_oLogFile, "%4d-%02d-%02d,%02d:%02d:%02d.%02d0,", utm.tm_year+1900, utm.tm_mon+1, utm.tm_mday, utm.tm_hour, utm.tm_min, utm.tm_sec, g_ms100);
|
f_printf(&g_oLogFile, "%4d-%02d-%02d,%02d:%02d:%02d.%02d0,", utm.tm_year+TM_YEAR_BASE, utm.tm_mon+1, utm.tm_mday, utm.tm_hour, utm.tm_min, utm.tm_sec, g_ms100);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
f_printf(&g_oLogFile, "%d,", tmr10ms);
|
f_printf(&g_oLogFile, "%d,", tmr10ms);
|
||||||
|
|
|
@ -141,7 +141,7 @@ static int luaGetDateTime(lua_State * L)
|
||||||
{
|
{
|
||||||
struct gtm utm;
|
struct gtm utm;
|
||||||
gettime(&utm);
|
gettime(&utm);
|
||||||
luaPushDateTime(L, utm.tm_year + 1900, utm.tm_mon + 1, utm.tm_mday, utm.tm_hour, utm.tm_min, utm.tm_sec);
|
luaPushDateTime(L, utm.tm_year + TM_YEAR_BASE, utm.tm_mon + 1, utm.tm_mday, utm.tm_hour, utm.tm_min, utm.tm_sec);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,6 @@ static_assert(TYPE_TWOS_COMPLEMENT(int), "twos complement arithmetic");
|
||||||
diagnostic on some hosts. */
|
diagnostic on some hosts. */
|
||||||
|
|
||||||
#define EPOCH_YEAR 1970
|
#define EPOCH_YEAR 1970
|
||||||
#define TM_YEAR_BASE 1900
|
|
||||||
static_assert(TM_YEAR_BASE % 100 == 0, "base year is not a multiple of 100");
|
static_assert(TM_YEAR_BASE % 100 == 0, "base year is not a multiple of 100");
|
||||||
|
|
||||||
/* Return 1 if YEAR + TM_YEAR_BASE is a leap year. */
|
/* Return 1 if YEAR + TM_YEAR_BASE is a leap year. */
|
||||||
|
@ -148,8 +147,8 @@ int __offtime(const gtime_t * t, long int offset, struct gtm * tp)
|
||||||
days -= ((yg - y) * 365 + LEAPS_THRU_END_OF(yg - 1) - LEAPS_THRU_END_OF(y - 1));
|
days -= ((yg - y) * 365 + LEAPS_THRU_END_OF(yg - 1) - LEAPS_THRU_END_OF(y - 1));
|
||||||
y = yg;
|
y = yg;
|
||||||
}
|
}
|
||||||
tp->tm_year = y - 1900;
|
tp->tm_year = y - TM_YEAR_BASE;
|
||||||
if (tp->tm_year != y - 1900) {
|
if (tp->tm_year != y - TM_YEAR_BASE) {
|
||||||
/* The year cannot be represented due to overflow. */
|
/* The year cannot be represented due to overflow. */
|
||||||
// __set_errno (EOVERFLOW);
|
// __set_errno (EOVERFLOW);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -465,7 +464,7 @@ uint8_t rtcAdjust(uint16_t year, uint8_t mon, uint8_t day, uint8_t hour, uint8_t
|
||||||
|
|
||||||
// convert given UTC time to local time (to seconds) and compare it with RTC
|
// convert given UTC time to local time (to seconds) and compare it with RTC
|
||||||
struct gtm t;
|
struct gtm t;
|
||||||
t.tm_year = year - 1900;
|
t.tm_year = year - TM_YEAR_BASE;
|
||||||
t.tm_mon = mon - 1;
|
t.tm_mon = mon - 1;
|
||||||
t.tm_mday = day;
|
t.tm_mday = day;
|
||||||
t.tm_hour = hour;
|
t.tm_hour = hour;
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#define SECS_PER_HOUR 3600ul
|
#define SECS_PER_HOUR 3600ul
|
||||||
#define SECS_PER_DAY 86400ul
|
#define SECS_PER_DAY 86400ul
|
||||||
|
#define TM_YEAR_BASE 1900
|
||||||
|
|
||||||
typedef long int gtime_t;
|
typedef long int gtime_t;
|
||||||
|
|
||||||
|
|
|
@ -425,7 +425,7 @@ char * strAppendDate(char * str, bool time)
|
||||||
str[0] = '-';
|
str[0] = '-';
|
||||||
struct gtm utm;
|
struct gtm utm;
|
||||||
gettime(&utm);
|
gettime(&utm);
|
||||||
div_t qr = div(utm.tm_year+1900, 10);
|
div_t qr = div(utm.tm_year+TM_YEAR_BASE, 10);
|
||||||
str[4] = '0' + qr.rem;
|
str[4] = '0' + qr.rem;
|
||||||
qr = div(qr.quot, 10);
|
qr = div(qr.quot, 10);
|
||||||
str[3] = '0' + qr.rem;
|
str[3] = '0' + qr.rem;
|
||||||
|
|
|
@ -254,7 +254,7 @@ void rtcGetTime(struct gtm * utm)
|
||||||
|
|
||||||
g9x_rtcGetTime(&rtc);
|
g9x_rtcGetTime(&rtc);
|
||||||
|
|
||||||
utm->tm_year = rtc.year - 1900;
|
utm->tm_year = rtc.year - TM_YEAR_BASE;
|
||||||
utm->tm_mon = rtc.month - 1;
|
utm->tm_mon = rtc.month - 1;
|
||||||
utm->tm_mday = rtc.mday;
|
utm->tm_mday = rtc.mday;
|
||||||
utm->tm_hour = rtc.hour;
|
utm->tm_hour = rtc.hour;
|
||||||
|
@ -268,7 +268,7 @@ void rtcSetTime(const struct gtm * t)
|
||||||
g_ms100 = 0; // start of next second begins now
|
g_ms100 = 0; // start of next second begins now
|
||||||
|
|
||||||
RTC rtc;
|
RTC rtc;
|
||||||
rtc.year = t->tm_year + 1900;
|
rtc.year = t->tm_year + TM_YEAR_BASE;
|
||||||
rtc.month = t->tm_mon + 1;
|
rtc.month = t->tm_mon + 1;
|
||||||
rtc.mday = t->tm_mday;
|
rtc.mday = t->tm_mday;
|
||||||
rtc.hour = t->tm_hour;
|
rtc.hour = t->tm_hour;
|
||||||
|
|
|
@ -1203,7 +1203,7 @@ void RTC_GetDate(uint32_t RTC_Format, RTC_DateTypeDef * RTC_DateStruct)
|
||||||
time_t tme;
|
time_t tme;
|
||||||
time(&tme);
|
time(&tme);
|
||||||
struct tm * timeinfo = localtime(&tme);
|
struct tm * timeinfo = localtime(&tme);
|
||||||
RTC_DateStruct->RTC_Year = timeinfo->tm_year - 1900;
|
RTC_DateStruct->RTC_Year = timeinfo->tm_year - TM_YEAR_BASE;
|
||||||
RTC_DateStruct->RTC_Month = timeinfo->tm_mon + 1;
|
RTC_DateStruct->RTC_Month = timeinfo->tm_mon + 1;
|
||||||
RTC_DateStruct->RTC_Date = timeinfo->tm_mday;
|
RTC_DateStruct->RTC_Date = timeinfo->tm_mday;
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,7 +164,7 @@ extern "C" void TWI0_IRQHandler()
|
||||||
utm.tm_hour = Co_proc_status[3] ;
|
utm.tm_hour = Co_proc_status[3] ;
|
||||||
utm.tm_mday = Co_proc_status[4] ;
|
utm.tm_mday = Co_proc_status[4] ;
|
||||||
utm.tm_mon = Co_proc_status[5] - 1;
|
utm.tm_mon = Co_proc_status[5] - 1;
|
||||||
utm.tm_year = (Co_proc_status[6] + ( Co_proc_status[7] << 8 )) - 1900;
|
utm.tm_year = (Co_proc_status[6] + ( Co_proc_status[7] << 8 )) - TM_YEAR_BASE;
|
||||||
g_rtcTime = gmktime(&utm);
|
g_rtcTime = gmktime(&utm);
|
||||||
}
|
}
|
||||||
Coproc_temp = Co_proc_status[8];
|
Coproc_temp = Co_proc_status[8];
|
||||||
|
|
|
@ -246,8 +246,8 @@ void rtcSetTime(const struct gtm * t)
|
||||||
I2CTime.Time[2] = t->tm_hour ;
|
I2CTime.Time[2] = t->tm_hour ;
|
||||||
I2CTime.Time[3] = t->tm_mday ;
|
I2CTime.Time[3] = t->tm_mday ;
|
||||||
I2CTime.Time[4] = t->tm_mon+1 ;
|
I2CTime.Time[4] = t->tm_mon+1 ;
|
||||||
I2CTime.Time[5] = (uint8_t) (t->tm_year+1900);
|
I2CTime.Time[5] = (uint8_t) (t->tm_year+TM_YEAR_BASE);
|
||||||
I2CTime.Time[6] = (t->tm_year+1900) >> 8;
|
I2CTime.Time[6] = (t->tm_year+TM_YEAR_BASE) >> 8;
|
||||||
#if defined(REVX)
|
#if defined(REVX)
|
||||||
writeRTC((uint8_t *)&I2CTime.Time[0]) ;
|
writeRTC((uint8_t *)&I2CTime.Time[0]) ;
|
||||||
#elif defined(COPROCESSOR)
|
#elif defined(COPROCESSOR)
|
||||||
|
|
|
@ -470,7 +470,7 @@ void logTelemetryWriteStart()
|
||||||
if (lastTime != newTime) {
|
if (lastTime != newTime) {
|
||||||
struct gtm utm;
|
struct gtm utm;
|
||||||
gettime(&utm);
|
gettime(&utm);
|
||||||
f_printf(&g_telemetryFile, "\r\n%4d-%02d-%02d,%02d:%02d:%02d.%02d0:", utm.tm_year+1900, utm.tm_mon+1, utm.tm_mday, utm.tm_hour, utm.tm_min, utm.tm_sec, g_ms100);
|
f_printf(&g_telemetryFile, "\r\n%4d-%02d-%02d,%02d:%02d:%02d.%02d0:", utm.tm_year+TM_YEAR_BASE, utm.tm_mon+1, utm.tm_mday, utm.tm_hour, utm.tm_min, utm.tm_sec, g_ms100);
|
||||||
lastTime = newTime;
|
lastTime = newTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue