Archive for March, 2007

Bikeshed Color

Tuesday, March 13th, 2007

A shed I built in my backyard with the help of my brother Lou and neighbors and friends.Cyril Northcote Parkinson wrote “Parkinson’s Law, and Other Studies in Administration” that was published in October, 1962.

There is an example in the book that refers to a bike shed and an atomic power-plant. According to a posting on the freebsd mailing list,

Parkinson shows how you can go in to the board of directors and get approval for building a multi-million or even billion dollar atomic power plant, but if you want to build a bike shed you will be tangled up in endless discussions.

Parkinson explains that this is because an atomic plant is so vast, so expensive and so complicated that people cannot grasp it, and rather than try, they fall back on the assumption that somebody else checked all the details before it got this far.

A bike shed on the other hand. Anyone can build one of those over a weekend, and still have time to watch the game on TV. So no matter how well prepared, no matter how reasonable you are with your proposal, somebody will seize the chance to show that he is doing his job, that he is paying attention, that he is *here*.

I heard this color of the bikeshed analogy for the first time while watching a Google Video titled, “How Open Source Projects Survive Poisonous People (And You Can Too).” The video contains a lot of good tips for open source projects and for communities in general. Paul posted a nice summary of the points in the video.

Daylight savings time

Monday, March 12th, 2007

Nightstand and alarm clockIt’s that time of year again. Time to spring forward. Well, not exactly the same time as last year. The formula for daylight savings time changed for this year. That meant that I had to rewrite firmware that used daylight savings time. According to Wikipedia,

Beginning in 2007, DST will start on the second Sunday in March (March 11, 2007), and change back to standard time on the first Sunday in November (November 4, 2007). Under Section 110 of the Energy Policy Act of 2005, the U.S. Department of Energy is required to study the impact of the DST extension no later than nine months after the change takes effect. Congress has retained the right to revert to the DST schedule set in 1986 if it cannot be shown that there are significant energy savings from an extension of DST or if the extension may prove to be unpopular with the American public. One potential issue is that some northern regions on the western edge of time zones will for the first time since the 1974-75 “almost year round” DST experiment have sunrise times that occur after 8am.

In two of my controllers I use, the built in hardware clock of the PC/104 card automatically handles the daylight savings time change. I simply set a bit and it would automatically spring forward or fall back. Well, almost. One of the controllers used a realtime clock chip by Odin which didn’t come out of daylight savings time and got stuck at 1am on the last Sunday of October. Since I could no longer utilize the hardware clock, I had to handle the daylight savings time change in software. There were two cases that I needed to cover. The first case is handling the timer interrupt and springing forward one hour or falling back one hour. The timer interrupt code turned out to be much simpler than I first thought. It is a good thing to be simple in an interrupt. Here is part of the code:

  1. if (data.tm_year >= (2007-1900)) {    /* begin DST – Second Sunday in March */    /* ANSI is months since January */    if ((data.tm_mon == 2 /*March*/) &amp;&amp;        (data.tm_wday == 1 /*Sunday*/) &amp;&amp;        (data.tm_mday >= 8) &amp;&amp; /* second Sunday */        (data.tm_mday <= 14) &amp;&amp;        (data.tm_hour == 2) &amp;&amp; /* 2:00 am */        (data.tm_min == 0) &amp;&amp;        (data.tm_sec == 0)) {        /* do something here */         }}

The second case was to determine if the date and time was during daylight savings time or not. This is used when the date and time get set on the controller, and to display the daylight savings time status. The code is more complex than the interrupt routine. Here is part of the code:

  1. if (year >= 2007) {    /* simple bounds check */     if ((month >= 3) &amp;&amp; (month <= 11)) {        /* get the start date for DST – Second Sunday in March */         if (month == 3) {            for (i = 8; i <= MonthDays(month,year); i++) {                if (DayOfWeek(DaysSinceEpoch(year,month,i)) == SUNDAY) {                    if (day == i) {                        time_now = TO_SECONDS(hour,minute,second);                         time_dst = TO_SECONDS(3,0,0);                         if (time_now >= time_dst) {                            dst = true;                        }                    } else if (day > i) {                        dst = true;                    }                     break;                }            }        }    }}

Testing the Daylight Savings Time algorithm was fairly routine using Unit Testing:

  1. void testDaylightSavings(Test* pTest){  /* original DST */  ct_test(pTest, IsDaylightSavings(31,12,2003) == FALSE);  ct_test(pTest, IsDaylightSavings(26,10,2003) == FALSE);  ct_test(pTest, IsDaylightSavings(25,10,2003) == TRUE);  ct_test(pTest, IsDaylightSavings(10,7,2003) == TRUE);  ct_test(pTest, IsDaylightSavings(6,4,2003) == TRUE);  ct_test(pTest, IsDaylightSavings(1,4,2003) == FALSE);  ct_test(pTest, IsDaylightSavings(1,1,2003) == FALSE);  /* new for 2007 DST */  ct_test(pTest, IsDaylightSavings(1,1,2007) == FALSE);  ct_test(pTest, IsDaylightSavings(3,3,2007) == FALSE);  ct_test(pTest, IsDaylightSavings(7,3,2007) == FALSE);  ct_test(pTest, IsDaylightSavings(8,3,2007) == FALSE);  ct_test(pTest, IsDaylightSavings(9,3,2007) == FALSE);  ct_test(pTest, IsDaylightSavings(10,3,2007) == FALSE);  ct_test(pTest, IsDaylightSavings(11,3,2007) == TRUE);  ct_test(pTest, IsDaylightSavings(10,7,2007) == TRUE);  ct_test(pTest, IsDaylightSavings(3,11,2007) == TRUE);  ct_test(pTest, IsDaylightSavings(4,11,2007) == FALSE);  ct_test(pTest, IsDaylightSavings(7,11,2007) == FALSE);  ct_test(pTest, IsDaylightSavings(8,11,2007) == FALSE);  ct_test(pTest, IsDaylightSavings(30,11,2007) == FALSE);  ct_test(pTest, IsDaylightSavings(31,12,2007) == FALSE);
  2.  
  3.   return;}

Hope you are getting used to waking up earlier!