-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Put definition of inline functions in separate .ipp file (#168)
- Loading branch information
Showing
14 changed files
with
194 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
|
||
#include <Sts1CobcSw/FileSystem/FileSystem.hpp> | ||
|
||
|
||
namespace sts1cobcsw::fs | ||
{ | ||
template<typename T> | ||
inline auto ReadFromFile(T * t) -> int | ||
{ | ||
return lfs_file_read(&lfs, &lfsFile, t, sizeof(T)); | ||
} | ||
|
||
|
||
template<typename T> | ||
inline auto WriteToFile(T const & t) -> int | ||
{ | ||
return lfs_file_write(&lfs, &lfsFile, &t, sizeof(T)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#pragma once | ||
|
||
|
||
#include <Sts1CobcSw/Hal/Communication.hpp> | ||
|
||
|
||
namespace sts1cobcsw::hal | ||
{ | ||
template<typename T, std::size_t size> | ||
inline auto WriteTo(auto * communicationInterface, std::span<T, size> data) | ||
{ | ||
std::size_t nSentBytes = 0U; | ||
auto bytes = std::as_bytes(data); | ||
|
||
while(nSentBytes < bytes.size()) | ||
{ | ||
nSentBytes += | ||
communicationInterface->write(bytes.data() + nSentBytes, bytes.size() - nSentBytes); | ||
} | ||
} | ||
|
||
|
||
inline auto WriteTo(auto * communicationInterface, std::string_view message) | ||
{ | ||
std::size_t nSentBytes = 0U; | ||
while(nSentBytes < message.size()) | ||
{ | ||
nSentBytes += | ||
communicationInterface->write(message.data() + nSentBytes, message.size() - nSentBytes); | ||
} | ||
} | ||
|
||
|
||
template<std::size_t size> | ||
inline auto ReadFrom(auto * communicationInterface, std::span<std::byte, size> readBuffer) | ||
{ | ||
std::size_t nReadBytes = 0U; | ||
while(nReadBytes < size) | ||
{ | ||
nReadBytes += | ||
communicationInterface->read(data(readBuffer) + nReadBytes, size - nReadBytes); | ||
} | ||
} | ||
|
||
|
||
template<std::size_t size> | ||
inline auto ReadFrom(auto * communicationInterface, std::span<char, size> readBuffer) | ||
{ | ||
std::size_t nReadBytes = 0U; | ||
while(nReadBytes < size) | ||
{ | ||
nReadBytes += | ||
communicationInterface->read(data(readBuffer) + nReadBytes, size - nReadBytes); | ||
} | ||
} | ||
|
||
|
||
template<std::size_t size> | ||
inline auto WriteToReadFrom(auto * communicationInterface, | ||
std::string_view message, | ||
etl::string<size> * answer) | ||
{ | ||
answer->initialize_free_space(); | ||
auto nReceivedBytes = communicationInterface->writeRead( | ||
message.data(), message.size(), answer->data(), answer->capacity()); | ||
answer->trim_to_terminator(); | ||
|
||
return nReceivedBytes; | ||
} | ||
|
||
template<std::size_t nBytes> | ||
auto WriteToReadFrom(auto * communicationInterface, std::span<Byte, nBytes> data) | ||
-> std::array<Byte, nBytes> | ||
{ | ||
auto readData = std::array<Byte, nBytes>{}; | ||
communicationInterface->writeRead(std::data(data), nBytes, std::data(readData), nBytes); | ||
return readData; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
|
||
|
||
#include <Sts1CobcSw/Hal/GpioPin.hpp> | ||
|
||
|
||
namespace sts1cobcsw::hal | ||
{ | ||
inline GpioPin::GpioPin(RODOS::GPIO_PIN pinIndex) : pin_(pinIndex) | ||
{ | ||
} | ||
|
||
|
||
inline auto GpioPin::Direction(PinDirection pinDirection) -> void | ||
{ | ||
pin_.reset(); | ||
pin_.init(pinDirection == PinDirection::out, 1, 0); | ||
} | ||
|
||
|
||
inline auto GpioPin::Set() -> void | ||
{ | ||
pin_.setPins(1U); | ||
} | ||
|
||
|
||
inline auto GpioPin::Reset() -> void | ||
{ | ||
pin_.setPins(0U); | ||
} | ||
|
||
|
||
inline auto GpioPin::Read() const -> PinState | ||
{ | ||
return pin_.readPins() == 0U ? PinState::reset : PinState::set; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
|
||
#include <Sts1CobcSw/Serial/Byte.hpp> | ||
|
||
|
||
namespace sts1cobcsw | ||
{ | ||
inline constexpr auto operator"" _b(unsigned long long number) -> Byte | ||
{ | ||
return static_cast<Byte>(number); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
|
||
#include <Sts1CobcSw/Utility/Time.hpp> | ||
|
||
|
||
namespace sts1cobcsw::utility | ||
{ | ||
//! @brief Given a time in seconds since 01.01.1970, return a time in nanoseconds since 01.01.2000. | ||
inline auto UnixToRodosTime(std::int32_t unixTimeSeconds) -> std::int64_t | ||
{ | ||
return static_cast<std::int64_t>(unixTimeSeconds) * RODOS::SECONDS - rodosUnixOffset; | ||
} | ||
|
||
|
||
inline auto GetUnixUtc() -> std::int32_t | ||
{ | ||
auto unixUtc = (RODOS::sysTime.getUTC() + rodosUnixOffset) / RODOS::SECONDS; | ||
return static_cast<std::int32_t>(unixUtc); | ||
} | ||
} |