Skip to content

Commit 81abad0

Browse files
committed
Add new Svc::ComRetry component
Add new component that can be used by other components to resend a message on failure.
1 parent 626473f commit 81abad0

File tree

3 files changed

+151
-0
lines changed

3 files changed

+151
-0
lines changed

Svc/ComRetry/ComRetry.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// ======================================================================
2+
// \title ComRetry.cpp
3+
// \author valdaarhun
4+
// \brief cpp file for ComRetry component implementation class
5+
// ======================================================================
6+
7+
#include "Svc/ComRetry/ComRetry.hpp"
8+
#include "ComRetry.hpp"
9+
10+
namespace Svc {
11+
12+
// ----------------------------------------------------------------------
13+
// Component construction and destruction
14+
// ----------------------------------------------------------------------
15+
16+
ComRetry ::ComRetry(const char* const compName)
17+
: ComRetryComponentBase(compName),
18+
m_num_retries(1),
19+
m_retry_count(0),
20+
m_bufferState(OWNED) {}
21+
22+
ComRetry ::~ComRetry() {}
23+
24+
void ComRetry::configure(U32 num_retries) {
25+
this->m_num_retries = num_retries;
26+
}
27+
28+
// ----------------------------------------------------------------------
29+
// Handler implementations for typed input ports
30+
// ----------------------------------------------------------------------
31+
32+
void ComRetry ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) {
33+
// TODO: Check if m_buffer is valid before attempting delivery
34+
if (condition == Fw::Success::SUCCESS) {
35+
this->dataReturnOut_out(0, this->m_buffer, this->m_context);
36+
this->comStatusOut_out(0, condition);
37+
}
38+
// Delivery of last message failed
39+
else if (this->m_retry_count < this->m_num_retries) {
40+
FW_ASSERT(this->m_bufferState == Fw::Buffer::OwnershipState::OWNED);
41+
this->m_bufferState = Fw::Buffer::OwnershipState::NOT_OWNED;
42+
this->m_retry_count++;
43+
this->dataOut_out(0, this->m_buffer, this->m_context);
44+
}
45+
// All retries failed, send FAILURE to upstream component
46+
else {
47+
this->dataReturnOut_out(0, this->m_buffer, this->m_context);
48+
this->m_retry_count = 0;
49+
Fw::Success condition = Fw::Success::FAILURE;
50+
this->comStatusOut_out(0, condition);
51+
}
52+
}
53+
54+
void ComRetry ::dataIn_handler(FwIndexType portNum, Fw::Buffer& buffer, const ComCfg::FrameContext& context) {
55+
FW_ASSERT(this->m_bufferState == Fw::Buffer::OwnershipState::OWNED);
56+
this->m_bufferState = Fw::Buffer::OwnershipState::NOT_OWNED;
57+
this->dataOut_out(0, buffer, context);
58+
}
59+
60+
void ComRetry ::dataReturnIn_handler(FwIndexType portNum, Fw::Buffer& buffer, const ComCfg::FrameContext& context) {
61+
FW_ASSERT(this->m_bufferState == Fw::Buffer::OwnershipState::NOT_OWNED);
62+
this->m_bufferState = Fw::Buffer::OwnershipState::OWNED;
63+
this->m_buffer = buffer;
64+
this->m_context = context;
65+
}
66+
67+
} // namespace Svc

Svc/ComRetry/ComRetry.fpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Svc {
2+
@ A component for retrying message delivery on failure
3+
active component ComRetry {
4+
import Svc.Framer
5+
6+
# One async command/port is required for active components
7+
# This should be overridden by the developers with a useful command/port
8+
@ TODO
9+
async input port TODO: Svc.Sched
10+
11+
# @ Example parameter
12+
# param PARAMETER_NAME: U32
13+
}
14+
}

Svc/ComRetry/ComRetry.hpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// ======================================================================
2+
// \title ComRetry.hpp
3+
// \author valdaarhun
4+
// \brief hpp file for ComRetry component implementation class
5+
// ======================================================================
6+
7+
#ifndef Svc_ComRetry_HPP
8+
#define Svc_ComRetry_HPP
9+
10+
#include "Svc/ComRetry/ComRetryComponentAc.hpp"
11+
12+
namespace Svc {
13+
14+
class ComRetry final : public ComRetryComponentBase {
15+
public:
16+
// ----------------------------------------------------------------------
17+
// Component construction and destruction
18+
// ----------------------------------------------------------------------
19+
20+
//! Construct ComRetry object
21+
ComRetry(const char* const compName //!< The component name
22+
);
23+
24+
//! Destroy ComRetry object
25+
~ComRetry();
26+
27+
//! Configure the number of retries
28+
void configure(U32 num_retries //!< Number of retries allowed
29+
);
30+
31+
private:
32+
// ----------------------------------------------------------------------
33+
// Handler implementations for typed input ports
34+
// ----------------------------------------------------------------------
35+
36+
//! Handler implementation for comStatusIn
37+
//!
38+
//! Resend last delivered message on failure
39+
void comStatusIn_handler(FwIndexType portNum, //!< The port number
40+
Fw::Success& condition //!< Condition success/failure
41+
) override;
42+
43+
//! Handler implementation for dataIn
44+
//!
45+
//! Port to receive data to frame, in a Fw::Buffer with optional context
46+
void dataIn_handler(FwIndexType portNum, //!< The port number
47+
Fw::Buffer& data,
48+
const ComCfg::FrameContext& context) override;
49+
50+
//! Handler implementation for dataReturnIn
51+
//!
52+
//! Buffer coming from a deallocate call in a ComDriver component
53+
void dataReturnIn_handler(FwIndexType portNum, //!< The port number
54+
Fw::Buffer& data,
55+
const ComCfg::FrameContext& context) override;
56+
57+
private:
58+
// ----------------------------------------------------------------------
59+
// Member variables
60+
// ----------------------------------------------------------------------
61+
U32 m_num_retries; //!< Maximum number of retries
62+
U32 m_retry_count; //!< Track number of attempted retries
63+
ComCfg::FrameContext m_context; //!< Context for the current frame
64+
Fw::Buffer m_buffer; //!< Store incoming buffer
65+
Fw::Buffer::OwnershipState m_bufferState; //!< Track ownership of stored buffer
66+
};
67+
68+
} // namespace Svc
69+
70+
#endif

0 commit comments

Comments
 (0)