Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
ECSS Services
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AcubeSat-OBC
ECSS Services
Commits
e48115be
Commit
e48115be
authored
6 years ago
by
Theodoros Katzalis
Browse files
Options
Downloads
Patches
Plain Diff
Added assertions for invalid dates
parent
31082657
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
inc/ErrorHandler.hpp
+7
-1
7 additions, 1 deletion
inc/ErrorHandler.hpp
src/Helpers/TimeHelper.cpp
+20
-3
20 additions, 3 deletions
src/Helpers/TimeHelper.cpp
with
27 additions
and
4 deletions
inc/ErrorHandler.hpp
+
7
−
1
View file @
e48115be
...
...
@@ -56,7 +56,13 @@ public:
* An error in the header of a packet makes it unable to be parsed
*/
UnacceptablePacket
=
5
,
};
/**
* A date that isn't valid according to the Gregorian calendar or cannot be parsed by the
* TimeHelper
*/
InvalidDate
=
6
,
};
/**
* The error code for failed acceptance reports, as specified in ECSS 6.1.4.3d
...
...
This diff is collapsed.
Click to expand it.
src/Helpers/TimeHelper.cpp
+
20
−
3
View file @
e48115be
...
...
@@ -11,6 +11,20 @@ bool TimeHelper::IsLeapYear(uint16_t year) {
}
uint32_t
TimeHelper
::
mkUTCtime
(
struct
TimeAndDate
&
TimeInfo
)
{
// the date, that \p TimeInfo represents, should be greater than or equal to 1/1/2019 and the
// date should be valid according to Gregorian calendar
assertI
(
TimeInfo
.
year
>=
2019
,
ErrorHandler
::
InternalErrorType
::
InvalidDate
);
assertI
(
1
<=
TimeInfo
.
month
&&
TimeInfo
.
month
<=
12
,
ErrorHandler
::
InternalErrorType
::
InvalidDate
);
assertI
(
1
<=
TimeInfo
.
day
&&
TimeInfo
.
day
<=
31
,
ErrorHandler
::
InternalErrorType
::
InvalidDate
);
assertI
(
0
<=
TimeInfo
.
hour
&&
TimeInfo
.
hour
<=
24
,
ErrorHandler
::
InternalErrorType
::
InvalidDate
);
assertI
(
0
<=
TimeInfo
.
minute
&&
TimeInfo
.
minute
<=
60
,
ErrorHandler
::
InternalErrorType
::
InvalidDate
);
assertI
(
0
<=
TimeInfo
.
second
&&
TimeInfo
.
second
<=
60
,
ErrorHandler
::
InternalErrorType
::
InvalidDate
);
uint32_t
secs
=
1546300800
;
// elapsed seconds from Unix epoch until 1/1/2019 00:00:00 (UTC)
for
(
uint16_t
y
=
2019
;
y
<
TimeInfo
.
year
;
++
y
)
{
secs
+=
(
IsLeapYear
(
y
)
?
366
:
365
)
*
SECONDS_PER_DAY
;
...
...
@@ -29,6 +43,9 @@ uint32_t TimeHelper::mkUTCtime(struct TimeAndDate &TimeInfo) {
}
struct
TimeAndDate
TimeHelper
::
utcTime
(
uint32_t
seconds
)
{
// elapsed seconds should be between dates, that are after 1/1/2019 and Unix epoch
assertI
(
seconds
>=
1546300800
,
ErrorHandler
::
InternalErrorType
::
UnknownInternalError
);
seconds
-=
1546300800
;
// elapsed seconds from Unix epoch until 1/1/2019 00:00:00 (UTC)
struct
TimeAndDate
TimeInfo
=
{
0
};
TimeInfo
.
year
=
2019
;
...
...
@@ -61,16 +78,16 @@ struct TimeAndDate TimeHelper::utcTime(uint32_t seconds) {
}
// calculate days
TimeInfo
.
day
=
seconds
/
SECONDS_PER_DAY
;
TimeInfo
.
day
=
seconds
/
SECONDS_PER_DAY
;
seconds
-=
TimeInfo
.
day
*
SECONDS_PER_DAY
;
TimeInfo
.
day
++
;
// add 1 day because we start count from 1 January (and not 0 January!)
// calculate hours
TimeInfo
.
hour
=
seconds
/
SECONDS_PER_HOUR
;
TimeInfo
.
hour
=
seconds
/
SECONDS_PER_HOUR
;
seconds
-=
TimeInfo
.
hour
*
SECONDS_PER_HOUR
;
// calculate minutes
TimeInfo
.
minute
=
seconds
/
SECONDS_PER_MINUTE
;
TimeInfo
.
minute
=
seconds
/
SECONDS_PER_MINUTE
;
seconds
-=
TimeInfo
.
minute
*
SECONDS_PER_MINUTE
;
// calculate seconds
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment