Skip to content

Commit

Permalink
Fix modifiers of Duration and includes
Browse files Browse the repository at this point in the history
It must be default constructible for usage in `RODOS::Commbuffer` and
`strong::difference` perfectly models the properties of a duration. It
can be added and subtracted, scaled and divided with the underlying
type, and dividing two `Duration`s yields the unterlying type.
  • Loading branch information
PatrickKa committed Aug 24, 2024
1 parent 0fd29a2 commit 51b19b1
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Sts1CobcSw/CobcSoftware/EduCommunicationErrorThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <Sts1CobcSw/Utility/Debug.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>

#include <strong_type/type.hpp>

#include <rodos_no_using_namespace.h>


Expand Down
2 changes: 2 additions & 0 deletions Sts1CobcSw/CobcSoftware/EduHeartbeatThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <Sts1CobcSw/Utility/Debug.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>

#include <strong_type/type.hpp>

#include <rodos_no_using_namespace.h>

#include <cinttypes> // IWYU pragma: keep
Expand Down
2 changes: 2 additions & 0 deletions Sts1CobcSw/CobcSoftware/EduListenerThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <Sts1CobcSw/Hal/IoNames.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>

#include <strong_type/type.hpp>

#include <rodos_no_using_namespace.h>


Expand Down
5 changes: 3 additions & 2 deletions Sts1CobcSw/CobcSoftware/EduPowerManagementThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
#include <Sts1CobcSw/Utility/Debug.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>

#include <rodos_no_using_namespace.h>
#include <strong_type/difference.hpp>
#include <strong_type/type.hpp>

#include <cstdint>
#include <rodos_no_using_namespace.h>


namespace sts1cobcsw
Expand Down
6 changes: 3 additions & 3 deletions Sts1CobcSw/CobcSoftware/EduProgramQueueThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
#include <Sts1CobcSw/Utility/Debug.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>

#include <strong_type/difference.hpp>
#include <strong_type/type.hpp>

#include <rodos/support/support-libs/ringbuffer.h>
#include <rodos_no_using_namespace.h>

#include <etl/vector.h>

#include <algorithm>
#include <cinttypes> // IWYU pragma: keep
#include <cstdint>


namespace sts1cobcsw
Expand Down Expand Up @@ -171,7 +170,8 @@ auto ComputeStartDelay() -> Duration
auto nextProgramStartTime =
value_of(edu::programQueue[edu::queueIndex].startTime) - (rodosUnixOffset / SECONDS);
auto currentUtcTime = RODOS::sysTime.getUTC() / SECONDS;
return Duration(std::max((nextProgramStartTime - currentUtcTime), 0LL) * SECONDS);
auto delay = (nextProgramStartTime - currentUtcTime) * SECONDS;
return delay < 0 ? Duration(0) : Duration(delay);
// FIXME: I think the above lines should just be
// auto delay = ToRodosTime(edu::programQueue[edu::queueIndex].startTime) - CurrentRodosTime();
// return delay < 0 ? Duration(0) : delay;
Expand Down
2 changes: 0 additions & 2 deletions Sts1CobcSw/CobcSoftware/TopicsAndSubscribers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#include <rodos_no_using_namespace.h>

#include <cstdint>


namespace sts1cobcsw
{
Expand Down
4 changes: 2 additions & 2 deletions Sts1CobcSw/Hal/Uart.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ auto ReadFrom(RODOS::HAL_UART * uart, std::span<T, extent> data, Duration timeou
{
auto bytes = std::as_writable_bytes(data);
std::size_t nReadBytes = 0;
auto reactivationTime = RealTime(RODOS::NOW() + value_of(timeout));
auto reactivationTime = CurrentRodosTime() + timeout;
while(nReadBytes < bytes.size())
{
uart->suspendUntilDataReady(value_of(reactivationTime));
if(RealTime(RODOS::NOW()) >= reactivationTime)
if(CurrentRodosTime() >= reactivationTime)
{
return ErrorCode::timeout;
}
Expand Down
12 changes: 6 additions & 6 deletions Sts1CobcSw/Utility/Time.hpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#pragma once


// TODO: Just including timemodel.h might be better here because then Utility should be able to be
// combined with Catch2 without defining two main()s.
#include <Sts1CobcSw/Serial/Serial.hpp>

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

#include <rodos_no_using_namespace.h>

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


namespace sts1cobcsw
{
using Duration = strong::type<std::int64_t,
struct DurationTag,
strong::equality,
strong::strongly_ordered,
strong::arithmetic>;
strong::default_constructible, // For RODOS::CommBuffer
strong::difference>;
using RodosTime = strong::type<std::int64_t,
struct RodosTimeTag,
strong::affine_point<Duration>,
Expand Down

0 comments on commit 51b19b1

Please sign in to comment.