Skip to content

Commit

Permalink
Make cosmetic changes and add TODO comments
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickKa committed May 10, 2024
1 parent 205d037 commit 97dd611
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 33 deletions.
56 changes: 35 additions & 21 deletions Sts1CobcSw/Periphery/FramMock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,72 +8,84 @@

namespace sts1cobcsw::fram
{

constexpr auto framSize = (1U << 20U);
auto ramSimulation = std::array<uint8_t, framSize>{};
MockMode mockDevice = MockMode::ram;
constexpr auto mockFilename = "FramMock.bin";

auto FramMockMode(MockMode mockMode) -> void
{
mockDevice = mockMode;
}
auto doInitialize = DoInitializeDefault;
auto doReadDeviceId = DoReadDeviceIdDefault;
auto doActualBaudRate = DoActualBaudRateDefault;

// Default do functions, doing nothing
auto DoInitializeDefault() -> void

// --- Mocked functions ---

auto Initialize() -> void
{
return doInitialize();
}

auto DoReadDeviceIdDefault() -> DeviceId

auto ReadDeviceId() -> DeviceId
{
return DeviceId{};
return doReadDeviceId();
}

auto DoActualBaudRateDefault() -> int32_t

auto ActualBaudRate() -> int32_t
{
return 0;
return doActualBaudRate();
}


auto doInitialize = DoInitializeDefault;
auto doReadDeviceId = DoReadDeviceIdDefault;
auto doActualBaudRate = DoActualBaudRateDefault;

// --- Set functions ---

auto SetDoInitialize(void (*doInitializeFunction)()) -> void
{
doInitialize = doInitializeFunction;
}


auto SetDoReadDeviceId(DeviceId (*doReadDeviceIdFunction)()) -> void
{
doReadDeviceId = doReadDeviceIdFunction;
}


void SetDoActualBaudRate(int32_t (*doActualBaudRateFunction)())
{
doActualBaudRate = doActualBaudRateFunction;
}


auto Initialize() -> void
// --- Default do functions, doing nothing ---

auto DoInitializeDefault() -> void
{
return doInitialize();
}

auto ReadDeviceId() -> DeviceId

auto DoReadDeviceIdDefault() -> DeviceId
{
return doReadDeviceId();
return DeviceId{};
}

auto ActualBaudRate() -> int32_t

auto DoActualBaudRateDefault() -> int32_t
{
return doActualBaudRate();
return 0;
}


auto FramMockMode(MockMode mockMode) -> void
{
mockDevice = mockMode;
}


namespace internal
{
// TODO: This must also forward to a do function which can be set with a SetDoWriteTo function
auto WriteTo(Address address, void const * data, std::size_t nBytes) -> void
{
if(mockDevice == MockMode::file)
Expand All @@ -96,6 +108,8 @@ auto WriteTo(Address address, void const * data, std::size_t nBytes) -> void
}
}


// TODO: This must also forward to a do function which can be set with a SetDoReadFrom function
auto ReadFrom(Address address, void * data, std::size_t nBytes) -> void
{
if(mockDevice == MockMode::file)
Expand Down
29 changes: 17 additions & 12 deletions Sts1CobcSw/Periphery/FramMock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,41 @@

namespace sts1cobcsw::fram
{
enum class MockMode
{
ram,
file
};


// TODO: Add SetDoWriteTo and SetDoReadFrom functions
auto SetDoInitialize(void (*doInitializeFunction)()) -> void;
auto SetDoReadDeviceId(DeviceId (*doReadDeviceIdFunction)()) -> void;
auto SetDoActualBaudRate(int32_t (*doActualBaudRateFunction)()) -> void;

auto SetDoActualBaudRate(std::int32_t (*doActualBaudRateFunction)()) -> void;

// TODO: Move to namespace "default"
// Default "do" functions that do nothing, used to initialized function pointers
auto DoInitializeDefault() -> void;
auto DoReadDeviceIdDefault() -> DeviceId;
auto DoActualBaudRateDefault() -> int32_t;


enum class MockMode
{
ram,
file
};
auto DoActualBaudRateDefault() -> std::int32_t;

// TODO: Remove this
auto FramMockMode(MockMode mockMode) -> void;

// TODO: Implement ram::do functions
namespace ram
{
auto DoInitialize() -> void;
auto DoReadDeviceId() -> DeviceId;
auto DoActualBaudRate() -> int32_t;
auto DoActualBaudRate() -> std::int32_t;
}


// TODO: Since this isn't fully implemented yet, remove it. The RAM mock should be enough.
namespace file
{
auto DoInitialize() -> void;
auto DoReadDeviceId() -> DeviceId;
auto DoActualBaudRate() -> int32_t;
auto DoActualBaudRate() -> std::int32_t;
}
}

0 comments on commit 97dd611

Please sign in to comment.