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 DpManager #2546

Merged
merged 8 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions Svc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/CmdDispatcher/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/CmdSequencer/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/CmdSplitter/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Deframer/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/DpManager/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FatalHandler/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FileDownlinkPorts/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FileDownlink/")
Expand Down
27 changes: 27 additions & 0 deletions Svc/DpManager/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/DpManager.fpp"
"${CMAKE_CURRENT_LIST_DIR}/DpManager.cpp"
)

register_fprime_module()

set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/DpManager.fpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/DpManagerTestMain.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/DpManagerTester.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Rules/BufferGetStatus.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Rules/CLEAR_EVENT_THROTTLE.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Rules/ProductGetIn.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Rules/ProductRequestIn.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Rules/ProductSendIn.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Rules/SchedIn.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Rules/Testers.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Scenarios/Random.cpp"
)

set(UT_MOD_DEPS
STest
)

set(UT_AUTO_HELPERS ON)
register_fprime_ut()
93 changes: 93 additions & 0 deletions Svc/DpManager/DpManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// ======================================================================
// \title DpManager.cpp
// \author bocchino
// \brief cpp file for DpManager component implementation class
// ======================================================================

#include "FpConfig.hpp"
#include "Svc/DpManager/DpManager.hpp"

namespace Svc {

// ----------------------------------------------------------------------
// Construction, initialization, and destruction
// ----------------------------------------------------------------------

DpManager::DpManager(const char* const compName)
Dismissed Show dismissed Hide dismissed
: DpManagerComponentBase(compName),
numSuccessfulAllocations(0),
numFailedAllocations(0),
numDataProducts(0),
numBytes(0) {}
Dismissed Show dismissed Hide dismissed

DpManager::~DpManager() {}
Dismissed Show dismissed Hide dismissed

// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------

Fw::Success DpManager::productGetIn_handler(const NATIVE_INT_TYPE portNum,
Dismissed Show dismissed Hide dismissed
FwDpIdType id,
FwSizeType size,
Dismissed Show dismissed Hide dismissed
Fw::Buffer& buffer) {
return this->getBuffer(portNum, id, size, buffer);
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
}

void DpManager::productRequestIn_handler(const NATIVE_INT_TYPE portNum, FwDpIdType id, FwSizeType size) {
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
// Get a buffer
Fw::Buffer buffer;
const Fw::Success status = this->getBuffer(portNum, id, size, buffer);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter portNum has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter id has not been checked.
Dismissed Show dismissed Hide dismissed
// Send buffer on productResponseOut
this->productResponseOut_out(portNum, id, buffer, status);
}

void DpManager::productSendIn_handler(const NATIVE_INT_TYPE portNum, FwDpIdType id, const Fw::Buffer& buffer) {
Dismissed Show dismissed Hide dismissed
// id is unused
(void)id;

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter id has not been checked.
// Update state variables
++this->numDataProducts;
this->numBytes += buffer.getSize();

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter buffer has not been checked.
// Send the buffer on productSendOut
Fw::Buffer sendBuffer = buffer;
this->productSendOut_out(portNum, sendBuffer);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter portNum has not been checked.
}

void DpManager::schedIn_handler(const NATIVE_INT_TYPE portNum, NATIVE_UINT_TYPE context) {
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
// Emit telemetry
this->tlmWrite_NumSuccessfulAllocations(this->numSuccessfulAllocations);
this->tlmWrite_NumFailedAllocations(this->numFailedAllocations);
this->tlmWrite_NumDataProducts(this->numDataProducts);
this->tlmWrite_NumBytes(this->numBytes);
}

// ----------------------------------------------------------------------
// Handler implementations for commands
// ----------------------------------------------------------------------

void DpManager ::CLEAR_EVENT_THROTTLE_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) {
this->log_WARNING_HI_BufferAllocationFailed_ThrottleClear();
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
Dismissed Show dismissed Hide dismissed

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter cmdSeq has not been checked.
}

// ----------------------------------------------------------------------
// Private helper functions
// ----------------------------------------------------------------------

Fw::Success DpManager::getBuffer(FwIndexType portNum, FwDpIdType id, FwSizeType size, Fw::Buffer& buffer) {
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
// Set status
Fw::Success status(Fw::Success::FAILURE);
// Get a buffer
buffer = this->bufferGetOut_out(portNum, size);
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
if (buffer.isValid()) {
// Buffer is valid
++this->numSuccessfulAllocations;
Dismissed Show dismissed Hide dismissed
status = Fw::Success::SUCCESS;
Dismissed Show dismissed Hide dismissed
} else {
// Buffer is invalid
++this->numFailedAllocations;
Dismissed Show dismissed Hide dismissed
this->log_WARNING_HI_BufferAllocationFailed(id);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter id has not been checked.
}
return status;
}

} // end namespace Svc
101 changes: 101 additions & 0 deletions Svc/DpManager/DpManager.fpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
module Svc {

@ A component for managing data products
active component DpManager {

# ----------------------------------------------------------------------
# Scheduling ports
# ----------------------------------------------------------------------

@ Schedule in port
async input port schedIn: Svc.Sched

# ----------------------------------------------------------------------
# Ports for handling buffer requests
# ----------------------------------------------------------------------

@ Ports for responding to a data product get from a client component
sync input port productGetIn: [DpManagerNumPorts] Fw.DpGet

@ Ports for receiving data product buffer requests from a client component
async input port productRequestIn: [DpManagerNumPorts] Fw.DpRequest

@ Ports for sending requested data product buffers to a client component
output port productResponseOut: [DpManagerNumPorts] Fw.DpResponse

@ Ports for getting buffers from a Buffer Manager
output port bufferGetOut: [DpManagerNumPorts] Fw.BufferGet

# ----------------------------------------------------------------------
# Ports for forwarding filled data products
# ----------------------------------------------------------------------

@ Ports for receiving filled data product buffers from a client component
async input port productSendIn: [DpManagerNumPorts] Fw.DpSend

@ Ports for sending filled data product buffers to a downstream component
output port productSendOut: [DpManagerNumPorts] Fw.BufferSend

# ----------------------------------------------------------------------
# F' special ports
# ----------------------------------------------------------------------

@ Command receive port
command recv port cmdIn

@ Command registration port
command reg port cmdRegIn

@ Command response port
command resp port cmdResponseOut

@ Event port
event port eventOut

@ Telemetry port
telemetry port tlmOut

@ Text event port
text event port textEventOut

@ Time get port
time get port timeGetOut

# ----------------------------------------------------------------------
# Commands
# ----------------------------------------------------------------------

@ Clear event throttling
async command CLEAR_EVENT_THROTTLE opcode 0x00

# ----------------------------------------------------------------------
# Events
# ----------------------------------------------------------------------

@ Buffer allocation failed
event BufferAllocationFailed(
$id: U32 @< The container ID
) \
severity warning high \
format "Buffer allocation failed for container id {}" \
throttle 10

# ----------------------------------------------------------------------
# Telemetry
# ----------------------------------------------------------------------

@ The number of successful buffer allocations
telemetry NumSuccessfulAllocations: U32 update on change

@ The number of failed buffer allocations
telemetry NumFailedAllocations: U32 update on change

@ Number of data products handled
telemetry NumDataProducts: U32 update on change

@ Number of bytes handled
telemetry NumBytes: U64 update on change

}

}
134 changes: 134 additions & 0 deletions Svc/DpManager/DpManager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// ======================================================================
// \title DpManager.hpp
// \author bocchino
// \brief hpp file for DpManager component implementation class
// ======================================================================

#ifndef Svc_DpManager_HPP
#define Svc_DpManager_HPP

#include <atomic>

#include "Svc/DpManager/DpManagerComponentAc.hpp"
#include "config/FppConstantsAc.hpp"

namespace Svc {

class DpManager : public DpManagerComponentBase {
private:
// ----------------------------------------------------------------------
// Static assertions against the assumptions about the model
// ----------------------------------------------------------------------

static_assert(
DpManager::NUM_PRODUCTGETIN_INPUT_PORTS == static_cast<FwSizeType>(DpManagerNumPorts),

Check failure on line 24 in Svc/DpManager/DpManager.hpp

View workflow job for this annotation

GitHub Actions / Spell checking

`PRODUCTGETIN` is not a recognized word. (unrecognized-spelling)
"Number of product get in ports must equal DpManagerNumPorts"
);
static_assert(
DpManager::NUM_PRODUCTREQUESTIN_INPUT_PORTS == static_cast<FwSizeType>(DpManagerNumPorts),

Check failure on line 28 in Svc/DpManager/DpManager.hpp

View workflow job for this annotation

GitHub Actions / Spell checking

`PRODUCTREQUESTIN` is not a recognized word. (unrecognized-spelling)
"Number of product request in ports must equal DpManagerNumPorts"
);
static_assert(
DpManager::NUM_PRODUCTRESPONSEOUT_OUTPUT_PORTS == static_cast<FwSizeType>(DpManagerNumPorts),

Check failure on line 32 in Svc/DpManager/DpManager.hpp

View workflow job for this annotation

GitHub Actions / Spell checking

`PRODUCTRESPONSEOUT` is not a recognized word. (unrecognized-spelling)
"Number of product response out ports must equal DpManagerNumPorts"
);
static_assert(
DpManager::NUM_BUFFERGETOUT_OUTPUT_PORTS == static_cast<FwSizeType>(DpManagerNumPorts),

Check failure on line 36 in Svc/DpManager/DpManager.hpp

View workflow job for this annotation

GitHub Actions / Spell checking

`BUFFERGETOUT` is not a recognized word. (unrecognized-spelling)
"Number of buffer get out ports must equal DpManagerNumPorts"
);
static_assert(
DpManager::NUM_PRODUCTSENDIN_INPUT_PORTS == static_cast<FwSizeType>(DpManagerNumPorts),

Check failure on line 40 in Svc/DpManager/DpManager.hpp

View workflow job for this annotation

GitHub Actions / Spell checking

`PRODUCTSENDIN` is not a recognized word. (unrecognized-spelling)
"Number of product send in ports must equal DpManagerNumPorts"
);
static_assert(
DpManager::NUM_PRODUCTSENDOUT_OUTPUT_PORTS == static_cast<FwSizeType>(DpManagerNumPorts),

Check failure on line 44 in Svc/DpManager/DpManager.hpp

View workflow job for this annotation

GitHub Actions / Spell checking

`PRODUCTSENDOUT` is not a recognized word. (unrecognized-spelling)
"Number of product send out ports must equal DpManagerNumPorts"
);

public:
// ----------------------------------------------------------------------
// Construction, initialization, and destruction
// ----------------------------------------------------------------------

//! Construct a DpManager
explicit DpManager(const char* const compName //!< The component name
);

//! Destroy the DpManager
~DpManager() final;

PRIVATE:
// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------

//! Handler implementation for productGetIn
Fw::Success productGetIn_handler(const NATIVE_INT_TYPE portNum, //!< The port number
FwDpIdType id, //!< The container ID
FwSizeType size, //!< The size of the requested buffer
Fw::Buffer& buffer //!< The buffer
) final;

//! Handler implementation for productRequestIn
void productRequestIn_handler(const NATIVE_INT_TYPE portNum, //!< The port number
FwDpIdType id, //!< The container ID
FwSizeType size //!< The size of the requested buffer
) final;

//! Handler implementation for productSendIn
void productSendIn_handler(const NATIVE_INT_TYPE portNum, //!< The port number
FwDpIdType id, //!< The container ID
const Fw::Buffer& buffer //!< The buffer
) final;

//! Handler implementation for schedIn
void schedIn_handler(const NATIVE_INT_TYPE portNum, //!< The port number
NATIVE_UINT_TYPE context //!< The call order
) final;

PRIVATE:
// ----------------------------------------------------------------------
// Handler implementations for commands
// ----------------------------------------------------------------------

//! Handler implementation for command CLEAR_EVENT_THROTTLE
//!
//! Clear event throttling
void CLEAR_EVENT_THROTTLE_cmdHandler(FwOpcodeType opCode, //!< The opcode
U32 cmdSeq //!< The command sequence number
) override;

PRIVATE:
// ----------------------------------------------------------------------
// Private helper functions
// ----------------------------------------------------------------------

//! Get a buffer
//! \return Status
Fw::Success getBuffer(FwIndexType portNum, //!< The port number
FwDpIdType id, //!< The container ID (input)
FwSizeType size, //!< The requested size (input)
Fw::Buffer& buffer //!< The buffer (output)
);

PRIVATE:
// ----------------------------------------------------------------------
// Private member variables
// ----------------------------------------------------------------------

//! The number of successful buffer allocations
std::atomic<U32> numSuccessfulAllocations;

//! The number of failed buffer allocations
std::atomic<U32> numFailedAllocations;

//! The number of data products handled
U32 numDataProducts;

//! The number of bytes handled
U64 numBytes;
};

} // end namespace Svc

#endif
10 changes: 8 additions & 2 deletions Svc/DpManager/docs/sdd.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,13 @@ It does the following:
<a name="ground_interface"></a>
## 4. Ground Interface

### 4.1. Telemetry
### 4.1. Commands

| Kind | Name | Description |
|------|------|-------------|
| `async` | `CLEAR_EVENT_THROTTLE` | Clear event throttling |

### 4.2. Telemetry

| Name | Type | Description |
|------|------|-------------|
Expand All @@ -157,7 +163,7 @@ It does the following:
| `NumDataProds` | `U32` | Number of data products handled |
| `NumBytes` | `U32` | Number of bytes handled |

### 4.2. Events
### 4.3. Events

| Name | Severity | Description |
|------|----------|-------------|
Expand Down
Loading
Loading