60,61c60,62
< TsunamiIO::RTC::RTC(const string &n, Tsunami* tsunami, time_t t, Tick i)
< : _name(n), event(tsunami, i), addr(0)
---
> TsunamiIO::RTC::RTC(const string &n, Tsunami* tsunami, const vector<int> &t,
> bool bcd, Tick i)
> : _name(n), event(tsunami, i), addr(0), year_is_bcd(bcd)
66a68,102
> if (year_is_bcd) {
> // The RTC uses BCD for the last two digits in the year.
> // They python year is a full year.
> int _year = t[0] % 100;
> int tens = _year / 10;
> int ones = _year % 10;
>
> year = (tens << 4) + ones;
> } else {
> // Even though the datasheet says that the year field should be
> // interpreted as BCD, we just enter the number of years since
> // 1900 since linux seems to be happy with that (and I believe
> // that Tru64 was as well)
> year = t[0] - 1900;
> }
>
> mon = t[1];
> mday = t[2];
> hour = t[3];
> min = t[4];
> sec = t[5];
>
> // wday is defined to be in the range from 1 - 7 with 1 being Sunday.
> // the value coming from python is in the range from 0 - 6 with 0 being
> // Monday. Fix that here.
> wday = t[6] + 2;
> if (wday > 7)
> wday -= 7;
>
> DPRINTFN("Real-time clock set to %s", getDateString());
> }
>
> std::string
> TsunamiIO::RTC::getDateString()
> {
68d103
< gmtime_r(&t, &tm);
70,76c105
< sec = tm.tm_sec;
< min = tm.tm_min;
< hour = tm.tm_hour;
< wday = tm.tm_wday + 1;
< mday = tm.tm_mday;
< mon = tm.tm_mon + 1;
< year = tm.tm_year;
---
> memset(&tm, 0, sizeof(tm));
78c107,130
< DPRINTFN("Real-time clock set to %s", asctime(&tm));
---
> if (year_is_bcd) {
> // undo the BCD and conver to years since 1900 guessing that
> // anything before 1970 is actually after 2000
> int _year = (year >> 4) * 10 + (year & 0xf);
> if (_year < 70)
> _year += 100;
>
> tm.tm_year = _year;
> } else {
> // number of years since 1900
> tm.tm_year = year;
> }
>
> // unix is 0-11 for month
> tm.tm_mon = mon - 1;
> tm.tm_mday = mday;
> tm.tm_hour = hour;
> tm.tm_min = min;
> tm.tm_sec = sec;
>
> // to add more annoyance unix is 0 - 6 with 0 as sunday
> tm.tm_wday = wday - 1;
>
> return asctime(&tm);
427c479,480
< rtc(p->name + ".rtc", p->tsunami, p->init_time, p->frequency)
---
> rtc(p->name + ".rtc", p->tsunami, p->init_time, p->year_is_bcd,
> p->frequency)
652c705,706
< Param<time_t> time;
---
> VectorParam<int> time;
> Param<bool> year_is_bcd;
664a719
> INIT_PARAM(year_is_bcd, ""),
678a734
> p->year_is_bcd = year_is_bcd;