Skip to content

Commit

Permalink
Add TimeTypes.[hi]pp again
Browse files Browse the repository at this point in the history
We actually do need this to break the cyclic dependency between
`RealTime.hpp` and `FramLayout.hpp`.
  • Loading branch information
PatrickKa committed Sep 22, 2024
1 parent bd67eba commit 0cbbeb6
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 67 deletions.
19 changes: 1 addition & 18 deletions Sts1CobcSw/Utility/RealTime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


#include <Sts1CobcSw/Serial/Serial.hpp>
#include <Sts1CobcSw/Utility/RodosTime.hpp>
#include <Sts1CobcSw/Utility/TimeTypes.hpp>

#include <strong_type/affine_point.hpp>
#include <strong_type/difference.hpp>
Expand All @@ -17,26 +17,9 @@

namespace sts1cobcsw
{
using RealTime = strong::type<std::int32_t,
struct RealTimeTag,
strong::default_constructible,
strong::equality,
strong::strongly_ordered>;


template<>
inline constexpr std::size_t serialSize<RealTime> =
totalSerialSize<strong::underlying_type_t<RealTime>>;


[[nodiscard]] auto CurrentRealTime() -> RealTime;
[[nodiscard]] auto ToRodosTime(RealTime realTime) -> RodosTime;
[[nodiscard]] auto ToRealTime(RodosTime rodosTime) -> RealTime;

template<std::endian endianness>
[[nodiscard]] auto SerializeTo(void * destination, RealTime const & data) -> void *;
template<std::endian endianness>
[[nodiscard]] auto DeserializeFrom(void const * source, RealTime * data) -> void const *;
}


Expand Down
17 changes: 2 additions & 15 deletions Sts1CobcSw/Utility/RealTime.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <Sts1CobcSw/FramSections/FramLayout.hpp>
#include <Sts1CobcSw/Utility/RealTime.hpp>

#include <rodos/api/timemodel.h>


namespace sts1cobcsw
{
Expand All @@ -25,19 +27,4 @@ inline auto ToRealTime(RodosTime rodosTime) -> RealTime
return RealTime(value_of(rodosTime + persistentVariables.template Load<"realTimeOffset">())
/ RODOS::SECONDS);
}


template<std::endian endianness>
inline auto SerializeTo(void * destination, RealTime const & data) -> void *
{
return SerializeTo<endianness>(destination, value_of(data));
}


template<std::endian endianness>
inline auto DeserializeFrom(void const * source, RealTime * data) -> void const *
{
source = DeserializeFrom<endianness>(source, &(value_of(*data)));
return source;
}
}
21 changes: 2 additions & 19 deletions Sts1CobcSw/Utility/RodosTime.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once


#include <Sts1CobcSw/Serial/Serial.hpp>
#include <Sts1CobcSw/Utility/TimeTypes.hpp>

#include <strong_type/affine_point.hpp>
#include <strong_type/difference.hpp>
Expand All @@ -17,16 +19,6 @@

namespace sts1cobcsw
{
using Duration = strong::
type<std::int64_t, struct DurationTag, strong::difference, strong::default_constructible>;
using RodosTime = strong::type<std::int64_t,
struct RodosTimeTag,
strong::affine_point<Duration>,
strong::default_constructible,
strong::equality,
strong::strongly_ordered>;


// NOLINTBEGIN(readability-identifier-length)
constexpr auto s = Duration(RODOS::SECONDS);
constexpr auto ms = Duration(RODOS::MILLISECONDS);
Expand All @@ -39,19 +31,10 @@ constexpr auto days = Duration(RODOS::DAYS);
constexpr auto weeks = Duration(RODOS::WEEKS);
constexpr auto endOfTime = RodosTime(RODOS::END_OF_TIME);

template<>
inline constexpr std::size_t serialSize<Duration> =
totalSerialSize<strong::underlying_type_t<Duration>>;


[[nodiscard]] auto CurrentRodosTime() -> RodosTime;
auto SuspendUntil(RodosTime time) -> void;
auto SuspendFor(Duration duration) -> void;

template<std::endian endianness>
[[nodiscard]] auto SerializeTo(void * destination, Duration const & data) -> void *;
template<std::endian endianness>
[[nodiscard]] auto DeserializeFrom(void const * source, Duration * data) -> void const *;
}


Expand Down
15 changes: 0 additions & 15 deletions Sts1CobcSw/Utility/RodosTime.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,4 @@ inline auto SuspendFor(Duration duration) -> void
{
RODOS::AT(RODOS::NOW() + value_of(duration));
}


template<std::endian endianness>
inline auto SerializeTo(void * destination, Duration const & data) -> void *
{
return SerializeTo<endianness>(destination, value_of(data));
}


template<std::endian endianness>
inline auto DeserializeFrom(void const * source, Duration * data) -> void const *
{
source = DeserializeFrom<endianness>(source, &(value_of(*data)));
return source;
}
}
53 changes: 53 additions & 0 deletions Sts1CobcSw/Utility/TimeTypes.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#pragma once


#include <Sts1CobcSw/Serial/Serial.hpp>

#include <strong_type/affine_point.hpp>
#include <strong_type/difference.hpp>
#include <strong_type/equality.hpp>
#include <strong_type/ordered.hpp>
#include <strong_type/type.hpp>

#include <bit>
#include <cstddef>
#include <cstdint>


namespace sts1cobcsw
{
using Duration = strong::
type<std::int64_t, struct DurationTag, strong::difference, strong::default_constructible>;
using RodosTime = strong::type<std::int64_t,
struct RodosTimeTag,
strong::affine_point<Duration>,
strong::default_constructible,
strong::equality,
strong::strongly_ordered>;
using RealTime = strong::type<std::int32_t,
struct RealTimeTag,
strong::default_constructible,
strong::equality,
strong::strongly_ordered>;


template<>
inline constexpr std::size_t serialSize<RealTime> =
totalSerialSize<strong::underlying_type_t<RealTime>>;
template<>
inline constexpr std::size_t serialSize<Duration> =
totalSerialSize<strong::underlying_type_t<Duration>>;


template<std::endian endianness>
[[nodiscard]] auto SerializeTo(void * destination, RealTime const & data) -> void *;
template<std::endian endianness>
[[nodiscard]] auto DeserializeFrom(void const * source, RealTime * data) -> void const *;
template<std::endian endianness>
[[nodiscard]] auto SerializeTo(void * destination, Duration const & data) -> void *;
template<std::endian endianness>
[[nodiscard]] auto DeserializeFrom(void const * source, Duration * data) -> void const *;
}


#include <Sts1CobcSw/Utility/TimeTypes.ipp> // IWYU pragma: keep
37 changes: 37 additions & 0 deletions Sts1CobcSw/Utility/TimeTypes.ipp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once


#include <Sts1CobcSw/Utility/TimeTypes.hpp>


namespace sts1cobcsw
{
template<std::endian endianness>
inline auto SerializeTo(void * destination, RealTime const & data) -> void *
{
return SerializeTo<endianness>(destination, value_of(data));
}


template<std::endian endianness>
inline auto DeserializeFrom(void const * source, RealTime * data) -> void const *
{
source = DeserializeFrom<endianness>(source, &(value_of(*data)));
return source;
}


template<std::endian endianness>
inline auto SerializeTo(void * destination, Duration const & data) -> void *
{
return SerializeTo<endianness>(destination, value_of(data));
}


template<std::endian endianness>
inline auto DeserializeFrom(void const * source, Duration * data) -> void const *
{
source = DeserializeFrom<endianness>(source, &(value_of(*data)));
return source;
}
}

0 comments on commit 0cbbeb6

Please sign in to comment.