-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add stream crossover component (#2070)
* stream crossover component * Add StreamCrossover Documentation * Add unit tests, update expect.txt * Add coverage for send error * update test name from ToDo to TestBuffer * Check recvStatus, and deallocate on error * Check recvBuffer size, rename errorDeallocate
- Loading branch information
1 parent
a98975a
commit 7cca7cb
Showing
10 changed files
with
412 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -449,6 +449,7 @@ ERRORCHECK | |
errorlevel | ||
errornum | ||
ert | ||
ethanchee | ||
etime | ||
ETIMEDOUT | ||
eturn | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#### | ||
# F prime CMakeLists.txt: | ||
# | ||
# SOURCE_FILES: combined list of source and autocoding files | ||
# MOD_DEPS: (optional) module dependencies | ||
# | ||
#### | ||
set(SOURCE_FILES | ||
"${CMAKE_CURRENT_LIST_DIR}/StreamCrossover.fpp" | ||
"${CMAKE_CURRENT_LIST_DIR}/StreamCrossover.cpp" | ||
) | ||
|
||
register_fprime_module() | ||
|
||
# Register the unit test build | ||
set(UT_SOURCE_FILES | ||
"${CMAKE_CURRENT_LIST_DIR}/StreamCrossover.fpp" | ||
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Tester.cpp" | ||
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TestMain.cpp" | ||
) | ||
set(UT_AUTO_HELPERS ON) | ||
register_fprime_ut() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// ====================================================================== | ||
// \title StreamCrossover.cpp | ||
// \author ethanchee | ||
// \brief cpp file for StreamCrossover component implementation class | ||
// ====================================================================== | ||
|
||
|
||
#include <Drv/StreamCrossover/StreamCrossover.hpp> | ||
#include <FpConfig.hpp> | ||
|
||
namespace Drv { | ||
|
||
// ---------------------------------------------------------------------- | ||
// Construction, initialization, and destruction | ||
// ---------------------------------------------------------------------- | ||
|
||
StreamCrossover :: | ||
StreamCrossover( | ||
const char *const compName | ||
) : StreamCrossoverComponentBase(compName) | ||
{ | ||
|
||
} | ||
|
||
StreamCrossover :: | ||
~StreamCrossover() | ||
{ | ||
|
||
} | ||
|
||
// ---------------------------------------------------------------------- | ||
// Handler implementations for user-defined typed input ports | ||
// ---------------------------------------------------------------------- | ||
|
||
void StreamCrossover :: | ||
streamIn_handler( | ||
const NATIVE_INT_TYPE portNum, | ||
Fw::Buffer &recvBuffer, | ||
const Drv::RecvStatus &recvStatus | ||
) | ||
{ | ||
if(recvStatus == Drv::RecvStatus::RECV_ERROR || recvBuffer.getSize() == 0) | ||
{ | ||
this->log_WARNING_HI_StreamOutError(Drv::SendStatus::SEND_ERROR); | ||
this->errorDeallocate_out(0, recvBuffer); | ||
return; | ||
} | ||
|
||
Drv::SendStatus sendStatus = this->streamOut_out(0, recvBuffer); | ||
|
||
if(sendStatus != Drv::SendStatus::SEND_OK) | ||
{ | ||
this->log_WARNING_HI_StreamOutError(sendStatus); | ||
} | ||
} | ||
|
||
} // end namespace Drv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Drv { | ||
|
||
passive component StreamCrossover { | ||
|
||
output port streamOut: Drv.ByteStreamSend | ||
|
||
sync input port streamIn: Drv.ByteStreamRecv | ||
|
||
@ Indicates buffer failed to send to streamOut. | ||
event StreamOutError(sendStatus: Drv.SendStatus) \ | ||
severity warning high \ | ||
format "StreamCrossover StreamOut Error: {}" | ||
|
||
@ Allows for deallocation after bad receive status | ||
output port errorDeallocate: Fw.BufferSend | ||
|
||
@ Port for requesting the current time | ||
time get port timeCaller | ||
|
||
@ Port for sending textual representation of events | ||
text event port logTextOut | ||
|
||
@ Port for sending events to downlink | ||
event port logOut | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// ====================================================================== | ||
// \title StreamCrossover.hpp | ||
// \author ethanchee | ||
// \brief hpp file for StreamCrossover component implementation class | ||
// ====================================================================== | ||
|
||
#ifndef StreamCrossover_HPP | ||
#define StreamCrossover_HPP | ||
|
||
#include "Drv/StreamCrossover/StreamCrossoverComponentAc.hpp" | ||
|
||
namespace Drv { | ||
|
||
class StreamCrossover : | ||
public StreamCrossoverComponentBase | ||
{ | ||
|
||
public: | ||
|
||
// ---------------------------------------------------------------------- | ||
// Construction, initialization, and destruction | ||
// ---------------------------------------------------------------------- | ||
|
||
//! Construct object StreamCrossover | ||
//! | ||
StreamCrossover( | ||
const char *const compName /*!< The component name*/ | ||
); | ||
|
||
//! Destroy object StreamCrossover | ||
//! | ||
~StreamCrossover(); | ||
|
||
PRIVATE: | ||
|
||
// ---------------------------------------------------------------------- | ||
// Handler implementations for user-defined typed input ports | ||
// ---------------------------------------------------------------------- | ||
|
||
//! Handler implementation for streamIn | ||
//! | ||
void streamIn_handler( | ||
const NATIVE_INT_TYPE portNum, /*!< The port number*/ | ||
Fw::Buffer &recvBuffer, | ||
const Drv::RecvStatus &recvStatus | ||
); | ||
|
||
|
||
}; | ||
|
||
} // end namespace Drv | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
\page DrvStreamCrossover Drv::StreamCrossover Stream Crossover Component | ||
# Drv::StreamCrossover Stream Crossover Component | ||
|
||
The Stream Crossover component allows a connection of byte stream driver model ports of type ByteStreamRecv and | ||
ByteStreamSend. | ||
|
||
## Design | ||
|
||
The Drv::StreamCrossover utilizes the byte stream driver model to handle the incoming stream of bytes. Upon calling | ||
the "streamIn" port, the `Fw::Buffer` containing the data will be forwarded to the "streamOut" port. This enables a | ||
connection from a ByteStreamRecv port to a ByteStreamSend port. | ||
|
||
## Port Descriptions | ||
| Name | Description | | ||
|---|---| | ||
| streamOut | A ByteStreamSend port for outgoing data stored in `Fw::Buffer` | | ||
| streamIn | A ByteStreamRecv port for incoming data stored in `Fw::Buffer` | | ||
| errorDeallocate | Deallocate a `Fw::Buffer` on error | | ||
|
||
## Requirements | ||
Add requirements in the chart below | ||
| Name | Description | Validation | | ||
|---|---|---| | ||
| STREAM-CROSSOVER-COMP-001 | The stream crossover component shall provide the capability to forward bytes | Unit Test | | ||
|
||
## Change Log | ||
| Date | Description | | ||
|---|---| | ||
| 2023-06-05 | Initial Draft | | ||
| 2023-06-09 | Implement Error Handling | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// ---------------------------------------------------------------------- | ||
// TestMain.cpp | ||
// ---------------------------------------------------------------------- | ||
|
||
#include "Tester.hpp" | ||
|
||
TEST(Nominal, TestBuffer) { | ||
Drv::Tester tester; | ||
tester.sendTestBuffer(); | ||
} | ||
|
||
TEST(Nominal, TestFail) { | ||
Drv::Tester tester; | ||
tester.testFail(); | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
::testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// ====================================================================== | ||
// \title StreamCrossover.hpp | ||
// \author ethanchee | ||
// \brief cpp file for StreamCrossover test harness implementation class | ||
// ====================================================================== | ||
|
||
#include "Tester.hpp" | ||
|
||
namespace Drv { | ||
|
||
// ---------------------------------------------------------------------- | ||
// Construction and destruction | ||
// ---------------------------------------------------------------------- | ||
|
||
Tester :: | ||
Tester() : | ||
StreamCrossoverGTestBase("Tester", Tester::MAX_HISTORY_SIZE), | ||
component("StreamCrossover") | ||
{ | ||
this->initComponents(); | ||
this->connectPorts(); | ||
} | ||
|
||
Tester :: | ||
~Tester() | ||
{ | ||
|
||
} | ||
|
||
// ---------------------------------------------------------------------- | ||
// Tests | ||
// ---------------------------------------------------------------------- | ||
|
||
void Tester :: | ||
sendTestBuffer() | ||
{ | ||
U8 testStr[6] = "test\n"; | ||
Fw::Buffer sendBuffer(testStr, sizeof(testStr)); | ||
this->invoke_to_streamIn(0, sendBuffer, Drv::RecvStatus::RECV_OK); | ||
|
||
// Ensure only one buffer was sent to streamOut | ||
ASSERT_from_streamOut_SIZE(1); | ||
|
||
// Ensure the sendBuffer was sent | ||
ASSERT_from_streamOut(0, sendBuffer); | ||
} | ||
|
||
void Tester :: | ||
testFail() | ||
{ | ||
U8 testStr[6] = "test\n"; | ||
Fw::Buffer sendBuffer(testStr, sizeof(testStr)); | ||
this->invoke_to_streamIn(0, sendBuffer, Drv::RecvStatus::RECV_ERROR); | ||
|
||
// Ensure only one buffer was sent to errorDeallocate port on RECV_ERROR | ||
ASSERT_from_errorDeallocate_SIZE(1); | ||
|
||
// Ensure the sendBuffer was sent | ||
ASSERT_from_errorDeallocate(0, sendBuffer); | ||
|
||
// Ensure the error event was sent | ||
ASSERT_EVENTS_StreamOutError_SIZE(1); | ||
|
||
// Ensure the error is SEND_ERROR | ||
ASSERT_EVENTS_StreamOutError(0, Drv::SendStatus::SEND_ERROR); | ||
} | ||
|
||
// ---------------------------------------------------------------------- | ||
// Handlers for typed from ports | ||
// ---------------------------------------------------------------------- | ||
|
||
Drv::SendStatus Tester :: | ||
from_streamOut_handler( | ||
const NATIVE_INT_TYPE portNum, | ||
Fw::Buffer &sendBuffer | ||
) | ||
{ | ||
this->pushFromPortEntry_streamOut(sendBuffer); | ||
|
||
U8 testStr[6] = "test\n"; | ||
Fw::Buffer cmpBuffer(testStr, sizeof(testStr)); | ||
|
||
if(!(cmpBuffer == sendBuffer)) | ||
{ | ||
return Drv::SendStatus::SEND_ERROR; | ||
} | ||
|
||
return Drv::SendStatus::SEND_OK; | ||
} | ||
|
||
void Tester :: | ||
from_errorDeallocate_handler( | ||
const NATIVE_INT_TYPE portNum, | ||
Fw::Buffer &fwBuffer | ||
) | ||
{ | ||
this->pushFromPortEntry_errorDeallocate(fwBuffer); | ||
} | ||
|
||
|
||
} // end namespace Drv |
Oops, something went wrong.