This is a library for managing the mbed real time clock, including functions for setting and getting the rtc in text format, getting and setting the timezone offset, and getting and setting the calibration register, both directly, and by using an adjustment API to automatically set the calibration value.
Diff: TimeUtilities.cpp
- Revision:
- 1:6d3d16f4b27c
- Parent:
- 0:108436d3cea9
- Child:
- 2:cbcdd97f3a6d
diff -r 108436d3cea9 -r 6d3d16f4b27c TimeUtilities.cpp --- a/TimeUtilities.cpp Sun May 29 20:11:27 2011 +0000 +++ b/TimeUtilities.cpp Sun May 29 20:34:27 2011 +0000 @@ -4,8 +4,16 @@ /// Also supports setting the clock, timezone offsets and calibration /// of the RTC subsystem. /// -/// @note Copyright © 2011 by Smartware Computing, all rights reserved. -/// @author David Smart +/// @note Copyright &copr; 2011 by Smartware Computing, all rights reserved. +/// Individuals may use this application for evaluation or non-commercial +/// purposes. Within this restriction, changes may be made to this application +/// as long as this copyright notice is retained. The user shall make +/// clear that their work is a derived work, and not the original. +/// Users of this application and sources accept this application "as is" and +/// shall hold harmless Smartware Computing, for any undesired results while +/// using this application - whether real or imagined. +/// +/// @author David Smart, Smartware Computing /// #ifndef WIN32 // embedded build @@ -21,8 +29,8 @@ #ifdef WIN32 // Fake it out for Win32 struct LPC { - unsigned long GPREG0; - unsigned long CALIBRATION; + unsigned long GPREG0; + unsigned long CALIBRATION; }; struct LPC X; struct LPC * LPC_RTC = &X; @@ -37,7 +45,7 @@ } RealTimeClock::RealTimeClock() { - GetTimeOffsetStore(); + GetTimeOffsetStore(); } RealTimeClock::~RealTimeClock() { @@ -116,27 +124,27 @@ t->tm_hour = atoi(p); p = strtok(NULL, " :"); if (p != NULL) { - t->tm_min = atoi(p); - p = strtok(NULL, " (:"); - if (p != NULL) { - t->tm_sec = atoi(p); - success = true; // if we get to here, we're good - p = strtok(NULL, " (:"); - if (p != NULL) { - success = false; // but can't accept a partial tzo - _oH = atoi(p); - p = strtok(NULL, " (:)"); - if (p != NULL) { - _oM = atoi(p); - success = true; // but a whole tzo is ok - SetTimeOffset(_oH, _oM); - } - } - seconds = mktime(t); - seconds = seconds - (time_t)(tzOffsetHr * 3600 + tzOffsetMin * 60); - set_time(seconds); - } - } + t->tm_min = atoi(p); + p = strtok(NULL, " (:"); + if (p != NULL) { + t->tm_sec = atoi(p); + success = true; // if we get to here, we're good + p = strtok(NULL, " (:"); + if (p != NULL) { + success = false; // but can't accept a partial tzo + _oH = atoi(p); + p = strtok(NULL, " (:)"); + if (p != NULL) { + _oM = atoi(p); + success = true; // but a whole tzo is ok + SetTimeOffset(_oH, _oM); + } + } + seconds = mktime(t); + seconds = seconds - (time_t)(tzOffsetHr * 3600 + tzOffsetMin * 60); + set_time(seconds); + } + } } } }