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
429d9315
Commit
429d9315
authored
6 years ago
by
Theodoros Katzalis
Browse files
Options
Downloads
Patches
Plain Diff
Replace magic numbers with #define
parent
f75f5bd6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.idea/codeStyles/Project.xml
+0
-19
0 additions, 19 deletions
.idea/codeStyles/Project.xml
inc/Helpers/TimeHelper.hpp
+4
-3
4 additions, 3 deletions
inc/Helpers/TimeHelper.hpp
src/Helpers/TimeHelper.cpp
+21
-21
21 additions, 21 deletions
src/Helpers/TimeHelper.cpp
with
25 additions
and
43 deletions
.idea/codeStyles/Project.xml
+
0
−
19
View file @
429d9315
...
...
@@ -3,25 +3,6 @@
<option
name=
"RIGHT_MARGIN"
value=
"100"
/>
<option
name=
"WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN"
value=
"true"
/>
<Objective-C-extensions>
<file>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"Import"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"Macro"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"Typedef"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"Enum"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"Constant"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"Global"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"Struct"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"FunctionPredecl"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"Function"
/>
</file>
<class>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"Property"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"Synthesize"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"InitMethod"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"StaticMethod"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"InstanceMethod"
/>
<option
name=
"com.jetbrains.cidr.lang.util.OCDeclarationKind"
value=
"DeallocMethod"
/>
</class>
<extensions>
<pair
source=
"cpp"
header=
"hpp"
fileNamingConvention=
"PASCAL_CASE"
/>
<pair
source=
"c"
header=
"h"
fileNamingConvention=
"NONE"
/>
...
...
This diff is collapsed.
Click to expand it.
inc/Helpers/TimeHelper.hpp
+
4
−
3
View file @
429d9315
...
...
@@ -4,6 +4,10 @@
#include
<cstdint>
#include
<Message.hpp>
#define SECONDS_PER_MINUTE 60
#define SECONDS_PER_HOUR 3600
#define SECONDS_PER_DAY 86400
/**
* The time and date provided from Real Time Clock(Real Time Clock).
*
...
...
@@ -37,9 +41,6 @@ struct TimeAndDate {
*/
class
TimeHelper
{
private:
const
uint8_t
SecondsPerMinute
=
60
;
const
uint16_t
SecondsPerHour
=
3600
;
const
uint32_t
SecondsPerDay
=
86400
;
const
uint8_t
DaysOfMonth
[
12
]
=
{
31
,
28
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
};
/**
...
...
This diff is collapsed.
Click to expand it.
src/Helpers/TimeHelper.cpp
+
21
−
21
View file @
429d9315
...
...
@@ -13,17 +13,17 @@ bool TimeHelper::IsLeapYear(uint16_t year) {
uint32_t
TimeHelper
::
mkUTCtime
(
struct
TimeAndDate
&
TimeInfo
)
{
uint32_t
secs
=
1546300800
;
// elapsed seconds from Unix epoch until 1/1/2019 00:00:00(UTC date)
for
(
uint16_t
y
=
2019
;
y
<
TimeInfo
.
year
;
++
y
)
{
secs
+=
(
IsLeapYear
(
y
)
?
366
:
365
)
*
S
econdsPerDay
;
secs
+=
(
IsLeapYear
(
y
)
?
366
:
365
)
*
S
ECONDS_PER_DAY
;
}
for
(
uint16_t
m
=
1
;
m
<
TimeInfo
.
month
;
++
m
)
{
secs
+=
DaysOfMonth
[
m
-
1
]
*
S
econdsPerDay
;
secs
+=
DaysOfMonth
[
m
-
1
]
*
S
ECONDS_PER_DAY
;
if
(
m
==
2
&&
IsLeapYear
(
TimeInfo
.
year
))
{
secs
+=
S
econdsPerDay
;
secs
+=
S
ECONDS_PER_DAY
;
}
}
secs
+=
(
TimeInfo
.
day
-
1
)
*
S
econdsPerDay
;
secs
+=
TimeInfo
.
hour
*
S
econdsPerHour
;
secs
+=
TimeInfo
.
minute
*
S
econdsPerMinute
;
secs
+=
(
TimeInfo
.
day
-
1
)
*
S
ECONDS_PER_DAY
;
secs
+=
TimeInfo
.
hour
*
S
ECONDS_PER_HOUR
;
secs
+=
TimeInfo
.
minute
*
S
ECONDS_PER_MINUTE
;
secs
+=
TimeInfo
.
second
;
return
secs
;
}
...
...
@@ -39,39 +39,39 @@ struct TimeAndDate TimeHelper::utcTime(uint32_t seconds) {
TimeInfo
.
second
=
0
;
// calculate years
while
(
seconds
>=
(
IsLeapYear
(
TimeInfo
.
year
)
?
366
:
365
)
*
S
econdsPerDay
)
{
seconds
-=
(
IsLeapYear
(
TimeInfo
.
year
)
?
366
:
365
)
*
S
econdsPerDay
;
while
(
seconds
>=
(
IsLeapYear
(
TimeInfo
.
year
)
?
366
:
365
)
*
S
ECONDS_PER_DAY
)
{
seconds
-=
(
IsLeapYear
(
TimeInfo
.
year
)
?
366
:
365
)
*
S
ECONDS_PER_DAY
;
TimeInfo
.
year
++
;
}
// calculate months
uint8_t
i
=
0
;
while
(
seconds
>=
(
DaysOfMonth
[
i
]
*
S
econdsPerDay
))
{
while
(
seconds
>=
(
DaysOfMonth
[
i
]
*
S
ECONDS_PER_DAY
))
{
TimeInfo
.
month
++
;
seconds
-=
(
DaysOfMonth
[
i
]
*
S
econdsPerDay
);
seconds
-=
(
DaysOfMonth
[
i
]
*
S
ECONDS_PER_DAY
);
i
++
;
if
(
i
==
1
&&
IsLeapYear
(
TimeInfo
.
year
))
{
if
(
seconds
<=
(
28
*
S
econdsPerDay
))
{
if
(
seconds
<=
(
28
*
S
ECONDS_PER_DAY
))
{
break
;
}
TimeInfo
.
month
++
;
seconds
-=
29
*
S
econdsPerDay
;
seconds
-=
29
*
S
ECONDS_PER_DAY
;
i
++
;
}
}
// calculate days
TimeInfo
.
day
=
seconds
/
S
econdsPerDay
;
seconds
-=
TimeInfo
.
day
*
S
econdsPerDay
;
TimeInfo
.
day
=
seconds
/
S
ECONDS_PER_DAY
;
seconds
-=
TimeInfo
.
day
*
S
ECONDS_PER_DAY
;
TimeInfo
.
day
++
;
// add 1 day because we start count from 1 January(and not 0 January!)
// calculate hours
TimeInfo
.
hour
=
seconds
/
S
econdsPerHour
;
seconds
-=
TimeInfo
.
hour
*
S
econdsPerHour
;
TimeInfo
.
hour
=
seconds
/
S
ECONDS_PER_HOUR
;
seconds
-=
TimeInfo
.
hour
*
S
ECONDS_PER_HOUR
;
// calculate minutes
TimeInfo
.
minute
=
seconds
/
S
econdsPerMinute
;
seconds
-=
TimeInfo
.
minute
*
S
econdsPerMinute
;
TimeInfo
.
minute
=
seconds
/
S
ECONDS_PER_MINUTE
;
seconds
-=
TimeInfo
.
minute
*
S
ECONDS_PER_MINUTE
;
// calculate seconds
TimeInfo
.
second
=
seconds
;
...
...
@@ -92,13 +92,13 @@ uint64_t TimeHelper::generateCDStimeFormat(struct TimeAndDate &TimeInfo) {
* The `DAY` segment, 16 bits as defined from standard. Actually the days passed since Unix
* epoch
*/
auto
elapsedDays
=
static_cast
<
uint16_t
>
(
seconds
/
86400
);
auto
elapsedDays
=
static_cast
<
uint16_t
>
(
seconds
/
SECONDS_PER_DAY
);
/**
* The `ms of day` segment, 32 bits as defined in standard. The `ms of the day` and DAY`
* should give the time passed since Unix epoch
*/
auto
msOfDay
=
static_cast
<
uint32_t
>
((
seconds
%
86400
)
*
1000
);
auto
msOfDay
=
static_cast
<
uint32_t
>
((
seconds
%
SECONDS_PER_DAY
)
*
1000
);
uint64_t
timeFormat
=
(
static_cast
<
uint64_t
>
(
elapsedDays
)
<<
32
|
msOfDay
);
...
...
@@ -113,7 +113,7 @@ struct TimeAndDate TimeHelper::parseCDStimeFormat(const uint8_t *data) {
(
static_cast
<
uint32_t
>
(
data
[
4
]))
<<
8
|
static_cast
<
uint32_t
>
(
data
[
5
]);
uint32_t
seconds
=
elapsedDays
*
86400
+
msOfDay
/
1000
;
uint32_t
seconds
=
elapsedDays
*
SECONDS_PER_DAY
+
msOfDay
/
1000
;
return
Access
.
utcTime
(
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