Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a DEBUG_PRINT() macro #234

Merged
merged 5 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"inherits": "warnings-unix",
"cacheVariables": {
"CMAKE_CXX_FLAGS": "$env{WARNINGS}",
"CMAKE_CXX_FLAGS_DEBUG": "-Og",
"CMAKE_CXX_FLAGS_DEBUG": "-Og -DDEBUG",
"CMAKE_CXX_FLAGS_RELEASE": "-Os"
}
},
Expand Down
2 changes: 1 addition & 1 deletion Sts1CobcSw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ add_subdirectory(Serial)
add_subdirectory(Utility)

target_sources(Sts1CobcSw_Dummy PRIVATE Dummy.cpp)
target_link_libraries(Sts1CobcSw_Dummy PUBLIC etl::etl)
target_link_libraries(Sts1CobcSw_Dummy PUBLIC etl::etl Sts1CobcSw_Utility)

target_sources(Sts1CobcSw_HelloDummy PRIVATE HelloDummy.cpp)
target_link_libraries(Sts1CobcSw_HelloDummy PRIVATE Sts1CobcSw_Dummy rodos::rodos)
Expand Down
28 changes: 14 additions & 14 deletions Sts1CobcSw/CommandParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <Sts1CobcSw/Edu/Edu.hpp>
#include <Sts1CobcSw/Edu/ProgramQueue.hpp>
#include <Sts1CobcSw/EduProgramQueueThread.hpp>
#include <Sts1CobcSw/Utility/Debug.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>

#include <rodos_no_using_namespace.h>
Expand All @@ -18,11 +19,10 @@ auto DispatchCommand(etl::vector<Byte, commandSize> const & command) -> void
auto gsCommandHeader =
Deserialize<GsCommandHeader>(std::span(command).first<serialSize<GsCommandHeader>>());

// TODO: Debug print, to be removed
RODOS::PRINTF("Header start character : %c\n", gsCommandHeader.startCharacter);
RODOS::PRINTF("Header commandID : %" PRIi8 "\n", gsCommandHeader.commandId);
RODOS::PRINTF("Header utc : %" PRIi32 "\n", gsCommandHeader.utc);
RODOS::PRINTF("Header length : %" PRIi16 "\n", gsCommandHeader.length);
DEBUG_PRINT("Header start character : %c\n", gsCommandHeader.startCharacter);
DEBUG_PRINT("Header commandID : %" PRIi8 "\n", gsCommandHeader.commandId);
DEBUG_PRINT("Header utc : %" PRIi32 "\n", gsCommandHeader.utc);
DEBUG_PRINT("Header length : %" PRIi16 "\n", gsCommandHeader.length);

// TODO: Move this somewhere else
RODOS::sysTime.setUTC(utility::UnixToRodosTime(gsCommandHeader.utc));
Expand Down Expand Up @@ -50,26 +50,26 @@ auto DispatchCommand(etl::vector<Byte, commandSize> const & command) -> void
}
default:
{
RODOS::PRINTF("*Error, invalid command*\n");
DEBUG_PRINT("*Error, invalid command*\n");
return;
}
}
}

RODOS::PRINTF("Not implemented yet.\n");
DEBUG_PRINT("Not implemented yet.\n");
}


auto BuildEduQueue(std::span<Byte const> commandData) -> void
{
RODOS::PRINTF("Entering build queue command parsing\n");
DEBUG_PRINT("Entering build queue command parsing\n");

edu::programQueue.clear();
ParseAndAddQueueEntries(commandData);
edu::queueIndex = 0;

RODOS::PRINTF("Queue index reset. Current size of EDU program queue is %d.\n",
static_cast<int>(edu::programQueue.size()));
DEBUG_PRINT("Queue index reset. Current size of EDU program queue is %d.\n",
static_cast<int>(edu::programQueue.size()));

ResumeEduProgramQueueThread();
}
Expand All @@ -81,16 +81,16 @@ auto BuildEduQueue(std::span<Byte const> commandData) -> void
//! and adds them to the global EDU program queue.
auto ParseAndAddQueueEntries(std::span<Byte const> queueEntries) -> void
{
RODOS::PRINTF("Printing and parsing\n");
DEBUG_PRINT("Printing and parsing\n");

while(queueEntries.size() >= serialSize<edu::QueueEntry> and (not edu::programQueue.full()))
{
auto entry =
Deserialize<edu::QueueEntry>(queueEntries.first<serialSize<edu::QueueEntry>>());

RODOS::PRINTF("Prog ID : %" PRIu16 "\n", entry.programId);
RODOS::PRINTF("Start Time : %" PRIi32 "\n", entry.startTime);
RODOS::PRINTF("Timeout : %" PRIi16 "\n", entry.timeout);
DEBUG_PRINT("Prog ID : %" PRIu16 "\n", entry.programId);
DEBUG_PRINT("Start Time : %" PRIi32 "\n", entry.startTime);
DEBUG_PRINT("Timeout : %" PRIi16 "\n", entry.timeout);

edu::programQueue.push_back(entry);
queueEntries = queueEntries.subspan<serialSize<edu::QueueEntry>>();
Expand Down
1 change: 0 additions & 1 deletion Sts1CobcSw/CommandParserThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class CommandParserThread : public RODOS::StaticThread<stackSize>
continue;
}

// RODOS::PRINTF("Read a character : %c\n", readCharacter);
if(readCharacter == startCharacter)
{
startWasDetected = true;
Expand Down
15 changes: 8 additions & 7 deletions Sts1CobcSw/Edu/Edu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <Sts1CobcSw/Serial/Byte.hpp>
#include <Sts1CobcSw/Serial/Serial.hpp>
#include <Sts1CobcSw/Utility/Crc32.hpp>
#include <Sts1CobcSw/Utility/Debug.hpp>
#include <Sts1CobcSw/Utility/Span.hpp>

#include <rodos_no_using_namespace.h>
Expand Down Expand Up @@ -109,7 +110,7 @@ auto TurnOff() -> void
auto StoreProgram(StoreProgramData const & data) -> Result<void>
{
auto errorCode = fs::deprecated::OpenProgramFile(data.programId, /* flags=*/0);
RODOS::PRINTF("Pretending to open the file ...\n");
DEBUG_PRINT("Pretending to open the file ...\n");
if(errorCode != 0)
{
return ErrorCode::fileSystemError;
Expand All @@ -119,8 +120,8 @@ auto StoreProgram(StoreProgramData const & data) -> Result<void>
while(true)
{
errorCode = fs::deprecated::ReadProgramFile(&cepDataBuffer);
RODOS::PRINTF("Pretending to read %d bytes from the file system ...\n",
static_cast<int>(cepDataBuffer.size()));
DEBUG_PRINT("Pretending to read %d bytes from the file system ...\n",
static_cast<int>(cepDataBuffer.size()));
if(errorCode != 0)
{
fs::deprecated::CloseProgramFile();
Expand All @@ -139,7 +140,7 @@ auto StoreProgram(StoreProgramData const & data) -> Result<void>
}

errorCode = fs::deprecated::CloseProgramFile();
RODOS::PRINTF("Pretending to close the file ...\n");
DEBUG_PRINT("Pretending to close the file ...\n");
if(errorCode != 0)
{
return ErrorCode::fileSystemError;
Expand Down Expand Up @@ -280,13 +281,13 @@ auto ReturnResult(ReturnResultData const & data) -> Result<void>
OUTCOME_TRY(SendCommand(cepAck));
// TODO: Not sure if we actually have a CRC32 over the whole file that needs to be
// checked here, but we need to send two ACKs anyway
RODOS::PRINTF("Pretending to check the whole file's CRC32 ...\n");
DEBUG_PRINT("Pretending to check the whole file's CRC32 ...\n");
OUTCOME_TRY(SendCommand(cepAck));
return outcome_v2::success();
}
// TODO: Actually store the result in the COBC file system
RODOS::PRINTF("Pretending to write %d bytes to the file system ...\n",
static_cast<int>(cepDataBuffer.size()));
DEBUG_PRINT("Pretending to write %d bytes to the file system ...\n",
static_cast<int>(cepDataBuffer.size()));
RODOS::AT(RODOS::NOW() + 3 * RODOS::MILLISECONDS);
OUTCOME_TRY(SendCommand(cepAck));
}
Expand Down
26 changes: 13 additions & 13 deletions Sts1CobcSw/Edu/EduMock.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <Sts1CobcSw/Edu/Edu.hpp> // IWYU pragma: associated
#include <Sts1CobcSw/Edu/Types.hpp>
#include <Sts1CobcSw/Utility/Debug.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>

#include <rodos_no_using_namespace.h>
Expand All @@ -9,14 +10,13 @@

namespace sts1cobcsw
{
using RODOS::PRINTF;
using utility::PrintFormattedSystemUtc;


// TODO: Move this to EduProgramQueueThreadMock.cpp or something
auto ResumeEduProgramQueueThread() -> void
{
PRINTF("Call to ResumeEduProgramQueueThread()\n");
DEBUG_PRINT("Call to ResumeEduProgramQueueThread()\n");
}


Expand All @@ -26,63 +26,63 @@ namespace edu
auto Initialize() -> void
{
PrintFormattedSystemUtc();
PRINTF("Call to Initialize()\n");
DEBUG_PRINT("Call to Initialize()\n");
}


auto TurnOn() -> void
{
PrintFormattedSystemUtc();
PRINTF("Call to TurnOn()\n");
DEBUG_PRINT("Call to TurnOn()\n");
}


auto TurnOff() -> void
{
PrintFormattedSystemUtc();
PRINTF("Call to TurnOff()\n");
DEBUG_PRINT("Call to TurnOff()\n");
}


auto StoreProgram(StoreProgramData const & data) -> Result<void>
{
PrintFormattedSystemUtc();
PRINTF("Call to StoreProgram(programId = %d)\n", data.programId);
DEBUG_PRINT("Call to StoreProgram(programId = %d)\n", data.programId);
return outcome_v2::success();
}


auto ExecuteProgram(ExecuteProgramData const & data) -> Result<void>
{
PrintFormattedSystemUtc();
PRINTF("Call to ExecuteProgram(programId = %d, startTime = %" PRIi32 ", timeout = %d)\n",
data.programId,
data.startTime,
data.timeout);
DEBUG_PRINT("Call to ExecuteProgram(programId = %d, startTime = %" PRIi32 ", timeout = %d)\n",
data.programId,
data.startTime,
data.timeout);
return outcome_v2::success();
}


auto StopProgram() -> Result<void>
{
PrintFormattedSystemUtc();
PRINTF("Call to StopProgram()\n");
DEBUG_PRINT("Call to StopProgram()\n");
return outcome_v2::success();
}


auto GetStatus() -> Result<Status>
{
PrintFormattedSystemUtc();
PRINTF("Call to GetStatus()\n");
DEBUG_PRINT("Call to GetStatus()\n");
return Status{.statusType = StatusType::invalid, .programId = 0, .startTime = 0, .exitCode = 0};
}


auto UpdateTime(UpdateTimeData const & data) -> Result<void>
{
PrintFormattedSystemUtc();
PRINTF("Call to UpdateTime(currentTime = %" PRIi32 ")\n", data.currentTime);
DEBUG_PRINT("Call to UpdateTime(currentTime = %" PRIi32 ")\n", data.currentTime);
return outcome_v2::success();
}
}
Expand Down
10 changes: 5 additions & 5 deletions Sts1CobcSw/EduCommunicationErrorThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <Sts1CobcSw/EduCommunicationErrorThread.hpp>
#include <Sts1CobcSw/ThreadPriorities.hpp>
#include <Sts1CobcSw/TopicsAndSubscribers.hpp>
#include <Sts1CobcSw/Utility/Debug.hpp>

#include <rodos_no_using_namespace.h>

Expand Down Expand Up @@ -33,11 +34,10 @@ class EduCommunicationErrorThread : public RODOS::StaticThread<stackSize>
while(true)
{
RODOS::AT(RODOS::END_OF_TIME);
// RODOS::PRINTF("EduCommunicationThread resumed in main loop\n");

eduCommunicationErrorCounter++;

RODOS::PRINTF("[EduCommunicationErrorThread] Resetting the Edu\n");
DEBUG_PRINT("[EduCommunicationErrorThread] Resetting the Edu\n");
// Reset EDU

edu::TurnOff();
Expand All @@ -48,14 +48,14 @@ class EduCommunicationErrorThread : public RODOS::StaticThread<stackSize>
[[maybe_unused]] auto status = edu::GetStatus();

// Busy wait
RODOS::PRINTF("[EduCommunicationErrorThread] Entering busy wait\n");
DEBUG_PRINT("[EduCommunicationErrorThread] Entering busy wait\n");
auto eduIsAlive = false;
while(not eduIsAlive)
{
yield(); // Force recalculation of scheduling!
eduIsAliveBufferForCommunicationError.get(eduIsAlive);
}
RODOS::PRINTF("[EduCommunicationErrorThread] Leaving busy wait\n");
DEBUG_PRINT("[EduCommunicationErrorThread] Leaving busy wait\n");
}
}
} eduCommunicationErrorThread;
Expand All @@ -64,6 +64,6 @@ class EduCommunicationErrorThread : public RODOS::StaticThread<stackSize>
auto ResumeEduCommunicationErrorThread() -> void
{
eduCommunicationErrorThread.resume();
RODOS::PRINTF("[EduCommunicationErrorThread] EduCommunicationErrorThread resumed\n");
DEBUG_PRINT("[EduCommunicationErrorThread] EduCommunicationErrorThread resumed\n");
}
}
21 changes: 11 additions & 10 deletions Sts1CobcSw/EduHeartbeatThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <Sts1CobcSw/Hal/IoNames.hpp>
#include <Sts1CobcSw/ThreadPriorities.hpp>
#include <Sts1CobcSw/TopicsAndSubscribers.hpp>
#include <Sts1CobcSw/Utility/Debug.hpp>

#include <rodos_no_using_namespace.h>

Expand Down Expand Up @@ -50,9 +51,9 @@ class EduHeartbeatThread : public RODOS::StaticThread<stackSize>
//
// auto type = EduIsAlive();
// if(type) {
// RODOS::PRINTF("Edu is alive\n");
// DEBUG_PRINT("Edu is alive\n");
// } else {
// RODOS::PRINTF("Edu is dead\n");
// DEBUG_PRINT("Edu is dead\n");
// }
// eduIsAliveTopic.publish(type);
//
Expand All @@ -69,7 +70,7 @@ class EduHeartbeatThread : public RODOS::StaticThread<stackSize>
auto oldHeartbeat = eduHeartbeatGpioPin.Read();
auto edgeCounter = 0;

RODOS::PRINTF("Sampling period : %" PRIi64 "\n", samplingPeriod / MILLISECONDS);
DEBUG_PRINT("Sampling period : %" PRIi64 "\n", samplingPeriod / MILLISECONDS);
auto toggle = true;
TIME_LOOP(0, samplingPeriod)
{
Expand All @@ -93,13 +94,13 @@ class EduHeartbeatThread : public RODOS::StaticThread<stackSize>
if(heartbeatIsConstant and (heartbeat != oldHeartbeat))
{
heartbeatIsConstant = false;
// RODOS::PRINTF("Detected an edge \n");
// DEBUG_PRINT("Detected an edge \n");
edgeCounter++;
}

if(edgeCounter == edgeCounterThreshold)
{
// RODOS::PRINTF("Edu is alive published to true\n");
// DEBUG_PRINT("Edu is alive published to true\n");
eduIsAliveTopic.publish(true);
edgeCounter = 0;
}
Expand All @@ -115,7 +116,7 @@ class EduHeartbeatThread : public RODOS::StaticThread<stackSize>
if(heartbeatIsConstant)
{
edgeCounter = 0;
// RODOS::PRINTF("Edu is alive published to false\n");
// DEBUG_PRINT("Edu is alive published to false\n");
eduIsAliveTopic.publish(false);
}
heartbeatIsConstant = true;
Expand Down Expand Up @@ -148,9 +149,9 @@ auto EduIsAlive() -> bool
}

auto executionTime = RODOS::NOW() - begin;
RODOS::PRINTF("Execution Time of EduIsAlive (ns) : %" PRIi64 "\n", executionTime);
RODOS::PRINTF("Execution Time of EduIsAlive (ms) : %" PRIi64 "\n",
executionTime / RODOS::MILLISECONDS);
DEBUG_PRINT("Execution Time of EduIsAlive (ns) : %" PRIi64 "\n", executionTime);
DEBUG_PRINT("Execution Time of EduIsAlive (ms) : %" PRIi64 "\n",
executionTime / RODOS::MILLISECONDS);
return false;
}
/*
Expand All @@ -174,7 +175,7 @@ class DummyThread : public RODOS::StaticThread<>
edu.TurnOn();
RODOS::AT(RODOS::NOW() + 25 * RODOS::SECONDS);

RODOS::PRINTF("Hello From DummyThread Timeloop\n");
DEBUG_PRINT("Hello From DummyThread Timeloop\n");
auto programId = 0_u16;
auto timestamp = 5_u16;
auto timeout = 10_i16;
Expand Down
Loading
Loading