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

Converting ByteStreamDriverModel into an interface #2252

Merged
merged 5 commits into from
Aug 29, 2023
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
7 changes: 7 additions & 0 deletions .github/workflows/reusable-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ on:
required: false
type: string
default: ""
target_ref:
description: "Branch on target to checkout"
required: false
type: string
default: "devel"

jobs:
build:
Expand All @@ -45,6 +50,7 @@ jobs:
with:
submodules: recursive
repository: ${{ inputs.target_repository }}
ref: ${{ inputs.target_ref }}
- name: "Overlay current F´ revision"
uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -75,6 +81,7 @@ jobs:
with:
submodules: recursive
repository: ${{ inputs.target_repository }}
ref: ${{ inputs.target_ref }}
- name: "Overlay current F´ revision"
uses: actions/checkout@v3
with:
Expand Down
86 changes: 36 additions & 50 deletions Drv/ByteStreamDriverModel/ByteStreamDriverModel.fpp
Original file line number Diff line number Diff line change
@@ -1,53 +1,39 @@
module Drv {

enum SendStatus {
SEND_OK = 0 @< Send worked as expected
SEND_RETRY = 1 @< Data send should be retried
SEND_ERROR = 2 @< Send error occurred retrying may succeed
}

port ByteStreamSend(
ref sendBuffer: Fw.Buffer
) -> SendStatus


enum RecvStatus {
RECV_OK = 0 @< Receive worked as expected
RECV_ERROR = 1 @< Receive error occurred retrying may succeed
}

port ByteStreamRecv(
ref recvBuffer: Fw.Buffer
recvStatus: RecvStatus
)


enum PollStatus {
POLL_OK = 0 @< Poll successfully received data
POLL_RETRY = 1 @< No data available, retry later
POLL_ERROR = 2 @< Error received when polling
}

port ByteStreamPoll(
ref pollBuffer: Fw.Buffer
) -> PollStatus

port ByteStreamReady()

passive component ByteStreamDriverModel {

output port ready: Drv.ByteStreamReady

output port $recv: Drv.ByteStreamRecv

guarded input port send: Drv.ByteStreamSend

guarded input port poll: Drv.ByteStreamPoll

output port allocate: Fw.BufferGet

output port deallocate: Fw.BufferSend

}

@ Status returned by the send call
enum SendStatus {
SEND_OK = 0 @< Send worked as expected
SEND_RETRY = 1 @< Data send should be retried
SEND_ERROR = 2 @< Send error occurred retrying may succeed
}

@ Send data out through the byte stream
port ByteStreamSend(
ref sendBuffer: Fw.Buffer @< Data to send
) -> SendStatus

@ Status associated with the received data
enum RecvStatus {
RECV_OK = 0 @< Receive worked as expected
RECV_ERROR = 1 @< Receive error occurred retrying may succeed
}

@ Carries the received bytes stream driver
port ByteStreamRecv(
ref recvBuffer: Fw.Buffer
recvStatus: RecvStatus
)

enum PollStatus {
POLL_OK = 0 @< Poll successfully received data
POLL_RETRY = 1 @< No data available, retry later
POLL_ERROR = 2 @< Error received when polling
}

port ByteStreamPoll(
ref pollBuffer: Fw.Buffer
) -> PollStatus

@ Signal indicating the driver is ready to send and received data
port ByteStreamReady()
}
8 changes: 8 additions & 0 deletions Drv/Interfaces/ByteStreamDriverInterface.fppi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@ Port invoked when the driver is ready to send/receive data
output port ready: Drv.ByteStreamReady

@ Port invoked when driver has received data
output port $recv: Drv.ByteStreamRecv

@ Port invoked to send data out the driver
guarded input port send: Drv.ByteStreamSend
9 changes: 1 addition & 8 deletions Drv/LinuxUartDriver/LinuxUartDriver.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@ module Drv {
# General ports
# ----------------------------------------------------------------------

@ Indicates the driver has connected to the UART device
output port ready: Drv.ByteStreamReady

@ Produces data received via the UART device on the receive task
output port $recv: Drv.ByteStreamRecv

@ Takes data to transmit out the UART device
guarded input port send: Drv.ByteStreamSend
include "../Interfaces/ByteStreamDriverInterface.fppi"

@ Allocation port used for allocating memory in the receive task
output port allocate: Fw.BufferGet
Expand Down
5 changes: 3 additions & 2 deletions Drv/TcpClient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
####
set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/../ByteStreamDriverModel/ByteStreamDriverModel.fpp"
"${CMAKE_CURRENT_LIST_DIR}/TcpClient.fpp"
"${CMAKE_CURRENT_LIST_DIR}/TcpClientComponentImpl.cpp"
)

Expand All @@ -21,12 +21,13 @@ register_fprime_module()

### UTs ###
set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/../ByteStreamDriverModel/ByteStreamDriverModel.fpp"
"${CMAKE_CURRENT_LIST_DIR}/TcpClient.fpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TestMain.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Tester.cpp"
)
set(UT_MOD_DEPS
STest
PortSelector
)
set(UT_AUTO_HELPERS ON)
register_fprime_ut()
11 changes: 11 additions & 0 deletions Drv/TcpClient/TcpClient.fpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Drv {
passive component TcpClient {

include "../Interfaces/ByteStreamDriverInterface.fppi"

output port allocate: Fw.BufferGet

output port deallocate: Fw.BufferSend

}
}
11 changes: 1 addition & 10 deletions Drv/TcpClient/TcpClientComponentImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ namespace Drv {
// ----------------------------------------------------------------------

TcpClientComponentImpl::TcpClientComponentImpl(const char* const compName)
: ByteStreamDriverModelComponentBase(compName),
: TcpClientComponentBase(compName),
SocketReadTask() {}

void TcpClientComponentImpl::init(const NATIVE_INT_TYPE instance) {
ByteStreamDriverModelComponentBase::init(instance);
}

SocketIpStatus TcpClientComponentImpl::configure(const char* hostname,
const U16 port,
const U32 send_timeout_seconds,
Expand Down Expand Up @@ -79,9 +75,4 @@ Drv::SendStatus TcpClientComponentImpl::send_handler(const NATIVE_INT_TYPE portN
return SendStatus::SEND_OK;
}

Drv::PollStatus TcpClientComponentImpl::poll_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) {
FW_ASSERT(0); // It is an error to call this handler on IP drivers
return PollStatus::POLL_ERROR;
}

} // end namespace Drv
18 changes: 2 additions & 16 deletions Drv/TcpClient/TcpClientComponentImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
#include <Drv/Ip/IpSocket.hpp>
#include <Drv/Ip/SocketReadTask.hpp>
#include <Drv/Ip/TcpClientSocket.hpp>
#include "Drv/ByteStreamDriverModel/ByteStreamDriverModelComponentAc.hpp"
#include "Drv/TcpClient/TcpClientComponentAc.hpp"

namespace Drv {

class TcpClientComponentImpl : public ByteStreamDriverModelComponentBase, public SocketReadTask {
class TcpClientComponentImpl : public TcpClientComponentBase, public SocketReadTask {
public:
// ----------------------------------------------------------------------
// Construction, initialization, and destruction
Expand All @@ -32,13 +32,6 @@ class TcpClientComponentImpl : public ByteStreamDriverModelComponentBase, public
*/
TcpClientComponentImpl(const char* const compName);


/**
* \brief Initialize this component
* \param instance: instance number of this component
*/
void init(const NATIVE_INT_TYPE instance = 0);

/**
* \brief Destroy the component
*/
Expand Down Expand Up @@ -132,13 +125,6 @@ class TcpClientComponentImpl : public ByteStreamDriverModelComponentBase, public
*/
Drv::SendStatus send_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer);

/**
* \brief **not supported**
*
* IP based ByteStreamDrivers don't support polling.
*/
Drv::PollStatus poll_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer);

Drv::TcpClientSocket m_socket; //!< Socket implementation
};

Expand Down
58 changes: 2 additions & 56 deletions Drv/TcpClient/test/ut/Tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

Os::Log logger;

#define INSTANCE 0
#define MAX_HISTORY_SIZE 1000

namespace Drv {

// ----------------------------------------------------------------------
Expand Down Expand Up @@ -99,8 +96,8 @@ void Tester ::test_with_loop(U32 iterations, bool recv_thread) {
}

Tester ::Tester()
: ByteStreamDriverModelGTestBase("Tester", MAX_HISTORY_SIZE),
component("ByteStreamDriverModel"),
: TcpClientGTestBase("Tester", MAX_HISTORY_SIZE),
component("TcpClient"),
m_data_buffer(m_data_storage, 0), m_spinner(true) {
this->initComponents();
this->connectPorts();
Expand Down Expand Up @@ -174,55 +171,4 @@ Fw::Buffer Tester ::
this->pushFromPortEntry_deallocate(fwBuffer);
}

// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------

void Tester ::
connectPorts()
{

// send
this->connect_to_send(
0,
this->component.get_send_InputPort(0)
);

// poll
this->connect_to_poll(
0,
this->component.get_poll_InputPort(0)
);

// recv
this->component.set_recv_OutputPort(
0,
this->get_from_recv(0)
);

// recv
this->component.set_ready_OutputPort(
0,
this->get_from_ready(0)
);

// allocate
this->component.set_allocate_OutputPort(
0,
this->get_from_allocate(0)
);

// deallocate
this->component.set_deallocate_OutputPort(
0,
this->get_from_deallocate(0)
);

}

void Tester ::initComponents() {
this->init();
this->component.init(INSTANCE);
}

} // end namespace Drv
8 changes: 7 additions & 1 deletion Drv/TcpClient/test/ut/Tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@
namespace Drv {

class Tester :
public ByteStreamDriverModelGTestBase
public TcpClientGTestBase
{
// Maximum size of histories storing events, telemetry, and port outputs
static const NATIVE_INT_TYPE MAX_HISTORY_SIZE = 1000;
// Instance ID supplied to the component instance under test
static const NATIVE_INT_TYPE TEST_INSTANCE_ID = 0;
// Queue depth supplied to component instance under test
static const NATIVE_INT_TYPE TEST_INSTANCE_QUEUE_DEPTH = 100;

// ----------------------------------------------------------------------
// Construction and destruction
Expand Down
5 changes: 3 additions & 2 deletions Drv/TcpServer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
####
set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/../ByteStreamDriverModel/ByteStreamDriverModel.fpp"
"${CMAKE_CURRENT_LIST_DIR}/TcpServer.fpp"
"${CMAKE_CURRENT_LIST_DIR}/TcpServerComponentImpl.cpp"
)

Expand All @@ -21,12 +21,13 @@ register_fprime_module()

### UTs ###
set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/../ByteStreamDriverModel/ByteStreamDriverModel.fpp"
"${CMAKE_CURRENT_LIST_DIR}/TcpServer.fpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TestMain.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Tester.cpp"
)
set(UT_MOD_DEPS
STest
PortSelector
)
set(UT_AUTO_HELPERS ON)
register_fprime_ut()
11 changes: 11 additions & 0 deletions Drv/TcpServer/TcpServer.fpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Drv {
passive component TcpServer {

include "../Interfaces/ByteStreamDriverInterface.fppi"

output port allocate: Fw.BufferGet

output port deallocate: Fw.BufferSend

}
}
11 changes: 1 addition & 10 deletions Drv/TcpServer/TcpServerComponentImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ namespace Drv {
// ----------------------------------------------------------------------

TcpServerComponentImpl::TcpServerComponentImpl(const char* const compName)
: ByteStreamDriverModelComponentBase(compName),
: TcpServerComponentBase(compName),
SocketReadTask() {}

void TcpServerComponentImpl::init(const NATIVE_INT_TYPE instance) {
ByteStreamDriverModelComponentBase::init(instance);
}

SocketIpStatus TcpServerComponentImpl::configure(const char* hostname,
const U16 port,
const U32 send_timeout_seconds,
Expand Down Expand Up @@ -86,9 +82,4 @@ Drv::SendStatus TcpServerComponentImpl::send_handler(const NATIVE_INT_TYPE portN
return SendStatus::SEND_OK;
}

Drv::PollStatus TcpServerComponentImpl::poll_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) {
FW_ASSERT(0); // It is an error to call this handler on IP drivers
return PollStatus::POLL_ERROR;
}

} // end namespace Drv
Loading
Loading