Skip to content

Commit

Permalink
Converting ByteStreamDriverModel into an interface
Browse files Browse the repository at this point in the history
  • Loading branch information
LeStarch committed Aug 24, 2023
1 parent ba8f1c6 commit 92b0a18
Show file tree
Hide file tree
Showing 20 changed files with 116 additions and 152 deletions.
53 changes: 0 additions & 53 deletions Drv/ByteStreamDriverModel/ByteStreamDriverModel.fpp

This file was deleted.

39 changes: 39 additions & 0 deletions Drv/ByteStreamDriverModel/ByteStreamDriverPorts.fpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Drv {

@ 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()
}
2 changes: 1 addition & 1 deletion Drv/ByteStreamDriverModel/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.fpp"
"${CMAKE_CURRENT_LIST_DIR}/ByteStreamDriverPorts.fpp"
)

register_fprime_module()
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
4 changes: 2 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,7 +21,7 @@ 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"
)
Expand Down
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
4 changes: 2 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,7 +21,7 @@ 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"
)
Expand Down
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
18 changes: 2 additions & 16 deletions Drv/TcpServer/TcpServerComponentImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
#include <Drv/Ip/IpSocket.hpp>
#include <Drv/Ip/SocketReadTask.hpp>
#include <Drv/Ip/TcpServerSocket.hpp>
#include "Drv/ByteStreamDriverModel/ByteStreamDriverModelComponentAc.hpp"
#include "Drv/TcpServer/TcpServerComponentAc.hpp"

namespace Drv {

class TcpServerComponentImpl : public ByteStreamDriverModelComponentBase, public SocketReadTask {
class TcpServerComponentImpl : public TcpServerComponentBase, public SocketReadTask {
public:
// ----------------------------------------------------------------------
// Construction, initialization, and destruction
Expand All @@ -33,13 +33,6 @@ class TcpServerComponentImpl : public ByteStreamDriverModelComponentBase, public
*/
TcpServerComponentImpl(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 @@ -152,13 +145,6 @@ class TcpServerComponentImpl : 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::TcpServerSocket m_socket; //!< Socket implementation
};

Expand Down
4 changes: 2 additions & 2 deletions Drv/Udp/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}/Udp.fpp"
"${CMAKE_CURRENT_LIST_DIR}/UdpComponentImpl.cpp"
)

Expand All @@ -21,7 +21,7 @@ register_fprime_module()

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

include "../Interfaces/ByteStreamDriverInterface.fppi"

output port allocate: Fw.BufferGet

output port deallocate: Fw.BufferSend

}
}
17 changes: 17 additions & 0 deletions Drv/Udp/Udp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ======================================================================
// Udp.hpp
// Standardization header for Udp
// ======================================================================

#ifndef Drv_Udp_HPP
#define Drv_Udp_HPP

#include "Drv/Udp/UdpComponentImpl.hpp"

namespace Drv {

typedef UdpComponentImpl Udp;

}

#endif
11 changes: 1 addition & 10 deletions Drv/Udp/UdpComponentImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@ namespace Drv {
// ----------------------------------------------------------------------

UdpComponentImpl::UdpComponentImpl(const char* const compName)
: ByteStreamDriverModelComponentBase(compName),
: UdpComponentBase(compName),
SocketReadTask() {}

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

SocketIpStatus UdpComponentImpl::configureSend(const char* hostname,
const U16 port,
const U32 send_timeout_seconds,
Expand Down Expand Up @@ -82,9 +78,4 @@ Drv::SendStatus UdpComponentImpl::send_handler(const NATIVE_INT_TYPE portNum, Fw
return SendStatus::SEND_OK;
}

Drv::PollStatus UdpComponentImpl::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

0 comments on commit 92b0a18

Please sign in to comment.