[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/handhelds/tos/lib/UIP NTPClientM.nc, 1.1, 1.2 TimeM.nc, 1.2, 1.3
steve ayer
ayer1 at users.sourceforge.net
Tue Apr 28 12:22:03 PDT 2009
Update of /cvsroot/tinyos/tinyos-1.x/contrib/handhelds/tos/lib/UIP
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv22597
Modified Files:
NTPClientM.nc TimeM.nc
Log Message:
NTPClientM.nc: commented out the assignment of the timeserver ip
address from infomem, which was almost certainly unpopulated in most
systems. for testing, assigned the four bytes a real server address,
though feel free to use your own!
TimeM.nc:
- updated some hard-coded year/date info needed to correctly convert
to localtime; year info structs were populated in 2004, they now carry
through 2012. also added correct julian days demarcating dst in the
u.s.
- changed variable g_first_year to now...
- eliminated the assignment of gmt offset from infomem, which is
probably empty, to 0. local implementations can handle this (exercise
for the reader).
- found two bugs in dst-handling code, defined HAVE_DST.
- first bug was the subtraction of an hour when in dst, instead of the
addition. (around line 214). this may reveal another bug, but...
- second definite bug was the always-correct tset of whether the current julian
day is in dst. it was day > first || day < first. it's now day >=
first && day <= last.
Index: NTPClientM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/handhelds/tos/lib/UIP/NTPClientM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NTPClientM.nc 29 Jul 2005 18:29:26 -0000 1.1
--- NTPClientM.nc 28 Apr 2009 19:22:01 -0000 1.2
***************
*** 103,107 ****
/* Send request to the NTP server */
! memcpy(addr.ip, infomem->ntp_ip, 4);
addr.port = 123;
--- 103,111 ----
/* Send request to the NTP server */
! // memcpy(addr.ip, infomem->ntp_ip, 4);
! addr.ip[0] = 128;
! addr.ip[1] = 31;
! addr.ip[2] = 0;
! addr.ip[3] = 21;
addr.port = 123;
Index: TimeM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/handhelds/tos/lib/UIP/TimeM.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TimeM.nc 20 Apr 2009 15:58:57 -0000 1.2
--- TimeM.nc 28 Apr 2009 19:22:01 -0000 1.3
***************
*** 36,39 ****
--- 36,40 ----
implementation {
+ #define HAVE_DST
extern int snprintf(char *str, size_t len, const char *format, ...) __attribute__ ((C));
***************
*** 65,69 ****
command result_t StdControl.init() {
! _time_tzinfo[0].gmt_offset = 60L * infomem->gmt_offset_minutes;
return SUCCESS;
}
--- 66,71 ----
command result_t StdControl.init() {
! // _time_tzinfo[0].gmt_offset = 60L * infomem->gmt_offset_minutes;
! _time_tzinfo[0].gmt_offset = 60L * 0L;
return SUCCESS;
}
***************
*** 121,154 ****
#define NUM_YEARS 4
/*
! import time
! for y in range(2004,2008):
! t = time.mktime((y, 1, 1, 0, 0, 0, 0, 0, 0))-5*3600
! print time.gmtime(t)
!
! (2004, 1, 1, 0, 0, 0, 3, 1, 0)
! (2005, 1, 1, 0, 0, 0, 5, 1, 0)
! (2006, 1, 1, 0, 0, 0, 6, 1, 0)
! (2007, 1, 1, 0, 0, 0, 0, 1, 0)
!
! NTP Timestamp starts Jan 1, 1900 and is 2208988800 jan 1 1970
! '%x' % (int(time.mktime((2004, 1, 1, 0, 0, 0, 3, 1, 0))) -18000 + 2208988800l)
!
! */
! const int16_t g_first_year = 2004;
const struct {
time_t year_seconds; /* time_t value for beginning of year */
int8_t wday_offset; /* tm_day of first day of the year */
int8_t isleap;
! int8_t dst_first_yday;
! int8_t dst_last_yday;
} year_info[NUM_YEARS] = {
/* unix time start jan 1 1970 */
! { 0x3ff36300, 3, 1 },
! { 0x41d5e800, 5, 0 },
! { 0x43b71b80, 6, 0 },
! { 0x45984f00, 0, 0 }
};
-
time_t g_seconds;
time_t g_year_seconds;
--- 123,168 ----
#define NUM_YEARS 4
/*
! import time
! for y in range(2004,2008):
! t = time.mktime((y, 1, 1, 0, 0, 0, 0, 0, 0))-5*3600
! print time.gmtime(t)
!
! (2004, 1, 1, 0, 0, 0, 3, 1, 0)
! (2005, 1, 1, 0, 0, 0, 5, 1, 0)
! (2006, 1, 1, 0, 0, 0, 6, 1, 0)
! (2007, 1, 1, 0, 0, 0, 0, 1, 0)
! from below in year_info struct for 2004-7
! { 0x3ff36300, 3, 1 },
! { 0x41d5e800, 5, 0 },
! { 0x43b71b80, 6, 0 },
! { 0x45984f00, 0, 0 }
!
! NTP Timestamp starts Jan 1, 1900 and is 2208988800 jan 1 1970
! '%x' % (int(time.mktime((2004, 1, 1, 0, 0, 0, 3, 1, 0))) -18000 + 2208988800l)
!
! and now,
!
! (2009, 1, 1, 0, 0, 0, 3, 1, 0)
! (2010, 1, 1, 0, 0, 0, 4, 1, 0)
! (2011, 1, 1, 0, 0, 0, 5, 1, 0)
! (2012, 1, 1, 0, 0, 0, 6, 1, 0)
!
! */
! const int16_t g_first_year = 2009;
const struct {
time_t year_seconds; /* time_t value for beginning of year */
int8_t wday_offset; /* tm_day of first day of the year */
int8_t isleap;
! int16_t dst_first_yday;
! int16_t dst_last_yday;
} year_info[NUM_YEARS] = {
/* unix time start jan 1 1970 */
! // from 2007, dst begins 2nd sunday in march, ends first sunday in november
! { 0x495c4dd0, 3, 0, 67, 305},
! { 0x4B3D8150, 4, 0, 73, 311},
! { 0x4D1EB4D0, 5, 0, 72, 310},
! { 0x4EFFE850, 6, 1, 71, 309}
};
time_t g_seconds;
time_t g_year_seconds;
***************
*** 165,168 ****
--- 179,184 ----
uint16_t hour, min;
int isleap = 0;
+
+ //if year_info has dst_first_yday and dst_last_yday defined, then HAVE_DST should be defined up top.
#ifdef HAVE_DST
int isdst = 0;
***************
*** 193,200 ****
g_seconds_from_day = seconds;
#ifdef HAVE_DST
! if (days > year_info[i].dst_first_yday
! || days < year_info[i].dst_first_yday) {
isdst = 1;
! seconds -= 3600;
if (seconds < 0) {
days--;
--- 209,216 ----
g_seconds_from_day = seconds;
#ifdef HAVE_DST
! if (days >= year_info[i].dst_first_yday &&
! days <= year_info[i].dst_last_yday) {
isdst = 1;
! seconds += 3600;
if (seconds < 0) {
days--;
More information about the Tinyos-contrib-commits
mailing list