Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ds3231 by
Revision 7:0551d7e7c13f, committed 2014-12-01
- Comitter:
- j3
- Date:
- Mon Dec 01 20:31:03 2014 +0000
- Parent:
- 6:e8850ad15893
- Child:
- 8:c7484a65fcea
- Commit message:
- Updated all set fx's to test for data range
Changed in this revision
| ds3231.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/ds3231.cpp Sat Nov 29 20:22:12 2014 +0000
+++ b/ds3231.cpp Mon Dec 01 20:31:03 2014 +0000
@@ -128,7 +128,7 @@
}
data_length++;
- //Test for good data.
+ //Make sure data is within range.
if((time.seconds > 59) || (time.minutes > 59) || (time.hours > max_hour))
{
return(1);
@@ -174,8 +174,18 @@
data[data_length++] = uchar_2_bcd(calendar.month);
data[data_length++] = uchar_2_bcd(calendar.year);
- //users responsibility to make sure calendar is logical
- return(write(w_adrs,(const char*) data, data_length));
+ //Make sure data is within range.
+ if(((calendar.day < 1) || (calendar.day > 7)) ||
+ ((calendar.date < 1) || (calendar.date > 31)) ||
+ ((calendar.month < 1) || (calendar.month > 12)) ||
+ (calendar.year > 99))
+ {
+ return(1);
+ }
+ else
+ {
+ return(write(w_adrs,(const char*) data, data_length));
+ }
}
@@ -320,8 +330,10 @@
mask_var = 0;
}
- //Test for good data.
- if((alarm.seconds > 59) || (alarm.minutes > 59) || (alarm.hours > max_hour) || (alarm.day > 7) || (alarm.date > 31))
+ //Make sure data is within range.
+ if((alarm.seconds > 59) || (alarm.minutes > 59) || (alarm.hours > max_hour) ||
+ ((alarm.day < 1) || (alarm.day > 7)) ||
+ ((alarm.date < 1) || (alarm.date > 31)))
{
return(1);
}
