Skip to content

Commit

Permalink
Update naming scheme for Result<T> variables
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromehue committed Dec 16, 2023
1 parent 21053e6 commit 3310f0c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
37 changes: 19 additions & 18 deletions Sts1CobcSw/Edu/Edu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,18 @@ auto GetStatus() -> Result<Status>

while(true)
{
auto status = GetStatusCommunication();
if(status)
auto getStatusCommunicationResult = GetStatusCommunication();
if(getStatusCommunicationResult)
{
auto status = getStatusCommunicationResult.value();
SendCommand(cmdAck);
RODOS::PRINTF(
" .statusType = %d\n .programId = %d\n .queueId = %d\n exitCode = "
"%d\n",
status.value().statusType,
status.value().programId,
status.value().queueId,
status.value().exitCode);
status.statusType,
status.programId,
status.queueId,
status.exitCode);
return status;
}
// Error in GetStatusCommunication()
Expand All @@ -242,8 +243,8 @@ auto GetStatus() -> Result<Status>

if(errorCount >= maxNNackRetries)
{
RODOS::PRINTF(" .errorCode = %d\n", status.error());
return status.error();
RODOS::PRINTF(" .errorCode = %d\n", getStatusCommunicationResult.error());
return getStatusCommunicationResult.error();
}
}
}
Expand Down Expand Up @@ -361,20 +362,20 @@ auto ReturnResult() -> Result<ResultInfo>
// DEBUG
// RODOS::PRINTF("\nPacket %d\n", static_cast<int>(packets));
// END DEBUG
auto resultInfo = ReturnResultRetry();
auto returnResultRetryResult = ReturnResultRetry();
// TYPE Result<something>
// DEBUG

// Break if an error is returned
if(resultInfo.has_error())
if(returnResultRetryResult.has_error())
{
auto errorCode = resultInfo.error();
auto errorCode = returnResultRetryResult.error();
RODOS::PRINTF(" ReturnResultRetry() resulted in an error : %d",
static_cast<int>(errorCode));
return resultInfo.error();
return returnResultRetryResult.error();
}
// or if EOF is reached
if(resultInfo.value().eofIsReached)
if(returnResultRetryResult.value().eofIsReached)
{
RODOS::PRINTF(" ReturnResultRetry() reached EOF\n");
return ResultInfo{.eofIsReached = true, .resultSize = totalResultSize};
Expand All @@ -384,7 +385,7 @@ auto ReturnResult() -> Result<ResultInfo>
// RODOS::PRINTF("\nWriting to file...\n");
// TODO: Actually write to a file

totalResultSize += resultInfo.value().resultSize;
totalResultSize += returnResultRetryResult.value().resultSize;
nPackets++;
}
return ResultInfo{.eofIsReached = false, .resultSize = totalResultSize};
Expand All @@ -403,12 +404,12 @@ auto ReturnResultRetry() -> Result<ResultInfo>
// errorCount <= maxNNackRetries as the termination condition
while(true)
{
auto resultInfo = ReturnResultCommunication();
if(resultInfo.has_value())
auto returnResultCommunicationResult = ReturnResultCommunication();
if(returnResultCommunicationResult.has_value())
{
SendCommand(cmdAck);
// returns {eofIsReached, resultSize}
return resultInfo.value();
return returnResultCommunicationResult.value();
}

// Error in ReturnResultCommunication()
Expand All @@ -417,7 +418,7 @@ auto ReturnResultRetry() -> Result<ResultInfo>
errorCount++;
if(errorCount == maxNNackRetries)
{
return resultInfo.error();
return returnResultCommunicationResult.error();
}
}

Expand Down
13 changes: 5 additions & 8 deletions Sts1CobcSw/EduListenerThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ class EduListenerThread : public RODOS::StaticThread<>
// RODOS::PRINTF("[EduListenerThread] Edu is alive and has an update\n");
// Communicate with EDU

auto statusResult = edu::GetStatus();
auto getStatusResult = edu::GetStatus();
// RODOS::PRINTF("EduStatus : %d, EduErrorcode %d\n", status.statusType,
// status.errorCode);

if(statusResult.has_error())
if(getStatusResult.has_error())
{
// RODOS::PRINTF("[EduListenerThread] GetStatus() error code : %d.\n",
// status.errorCode);
Expand All @@ -65,15 +65,12 @@ class EduListenerThread : public RODOS::StaticThread<>
// GetStatus().\n");
ResumeEduCommunicationErrorThread();
}
else

if(getStatusResult.has_value())
{
// RODOS::PRINTF("[EduListenerThread] Call to GetStatus() resulted in
// success.\n");
}

if(statusResult.has_value())
{
auto status = statusResult.value();
auto status = getStatusResult.value();
switch(status.statusType)
{
case edu::StatusType::programFinished:
Expand Down

0 comments on commit 3310f0c

Please sign in to comment.