Skip to content
Open
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
73 changes: 72 additions & 1 deletion Svc/GenericHub/GenericHub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void GenericHub::send_data(const HubType type, const FwIndexType port, const U8*
// ----------------------------------------------------------------------

void GenericHub::bufferIn_handler(const FwIndexType portNum, Fw::Buffer& fwBuffer) {
send_data(HUB_TYPE_BUFFER, portNum, fwBuffer.getData(), fwBuffer.getSize());
this->send_data(HUB_TYPE_BUFFER, portNum, fwBuffer.getData(), fwBuffer.getSize());
bufferInReturn_out(portNum, fwBuffer);
}

Expand All @@ -59,6 +59,43 @@ void GenericHub::bufferOutReturn_handler(FwIndexType portNum, Fw::Buffer& fwBuff
fromBufferDriverReturn_out(0, fwBuffer);
}

void GenericHub ::cmdDispIn_handler(FwIndexType portNum, Fw::ComBuffer& data, U32 context) {
Fw::SerializeStatus status;
// Buffer to send and a buffer used to write to it
U8 buffer[Fw::ComBuffer::SERIALIZED_SIZE];

Fw::ExternalSerializeBuffer serializer(buffer, sizeof(buffer));
serializer.resetSer();

status = serializer.serializeFrom(data.getBuffAddr(), data.getSize(), Fw::Serialization::OMIT_LENGTH);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(status));
status = serializer.serializeFrom(context);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(status));
FwSizeType size = serializer.getSize();

this->send_data(HUB_TYPE_CMD_DISP, portNum, buffer, size);
}

void GenericHub ::cmdRespIn_handler(FwIndexType portNum,
FwOpcodeType opCode,
U32 cmdSeq,
const Fw::CmdResponse& response) {
Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK;
U8 buffer[sizeof(opCode) + sizeof(cmdSeq) + sizeof(response)];
Fw::ExternalSerializeBuffer serializer(buffer, sizeof(buffer));
serializer.resetSer();

status = serializer.serializeFrom(opCode);
FW_ASSERT(status == Fw::SerializeStatus::FW_SERIALIZE_OK);
status = serializer.serializeFrom(cmdSeq);
FW_ASSERT(status == Fw::SerializeStatus::FW_SERIALIZE_OK);
status = serializer.serializeFrom(response);
FW_ASSERT(status == Fw::SerializeStatus::FW_SERIALIZE_OK);
FwSizeType size = serializer.getSize();

this->send_data(HUB_TYPE_CMD_RESP, portNum, buffer, size);
}

void GenericHub::fromBufferDriver_handler(const FwIndexType portNum, Fw::Buffer& fwBuffer) {
HubType type = HUB_TYPE_MAX;
U32 type_in = 0;
Expand Down Expand Up @@ -130,6 +167,40 @@ void GenericHub::fromBufferDriver_handler(const FwIndexType portNum, Fw::Buffer&
// Send it!
this->tlmOut_out(static_cast<FwIndexType>(port), id, timeTag, val);

// Return the received buffer
fromBufferDriverReturn_out(0, fwBuffer);
} else if (type == HUB_TYPE_CMD_DISP) {
U32 context;

// Com buffer representations should be copied before the call returns, so we need not "allocate" new data
Fw::ComBuffer wrapper(rawData, (rawSize - sizeof(U32)));
status = wrapper.setBuffLen(rawSize - sizeof(U32));
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(status));

incoming.deserializeSkip(rawSize - sizeof(U32));
status = incoming.deserializeTo(context);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(status));

this->cmdDispOut_out(static_cast<FwIndexType>(port), wrapper, context);

// Deallocate the existing buffer
fromBufferDriverReturn_out(0, fwBuffer);
} else if (type == HUB_TYPE_CMD_RESP) {
FwOpcodeType opCode;
U32 cmdSeq;
Fw::CmdResponse response;

// Deserialize tokens for channels
status = incoming.deserializeTo(opCode);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(status));
status = incoming.deserializeTo(cmdSeq);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(status));
status = incoming.deserializeTo(response);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(status));

// Send it!
this->cmdRespOut_out(static_cast<FwIndexType>(port), opCode, cmdSeq, response);

// Return the received buffer
fromBufferDriverReturn_out(0, fwBuffer);
}
Expand Down
18 changes: 18 additions & 0 deletions Svc/GenericHub/GenericHub.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ module Svc {
# genericHub.bufferInReturn[0] -> bufferProducer0.bufferIn
# bufferProducer1.bufferOut -> genericHub.bufferIn[1]
# genericHub.bufferInReturn[1] -> bufferProducer1.bufferIn
#
# command.cmdDispatch -> genericHub.cmdDispIn
# genericHub.cmdRespOut -> command.cmdResponseIn
# ----------------------------------------------------------------------

@ Port for sending events to the hub
Expand Down Expand Up @@ -96,6 +99,12 @@ module Svc {
@ bufferIn and bufferInReturn ports must match
match bufferIn with bufferInReturn

@ for sending remote commands
sync input port cmdDispIn: [CmdDispatcherSequencePorts] Fw.Com

@ Command response back from remote hub
output port cmdRespOut: [CmdDispatcherSequencePorts] Fw.CmdResponse

# ----------------------------------------------------------------------
# Ports for sending data from the hub to a buffer driver
# ----------------------------------------------------------------------
Expand Down Expand Up @@ -154,6 +163,9 @@ module Svc {
# bufferConsumer0.bufferInReturn -> genericHub.bufferOutReturn[0]
# genericHub.bufferOut[1] -> bufferConsumer1.bufferIn
# bufferConsumer1.bufferInReturn -> genericHub.bufferOutReturn[1]
#
# genericHub.cmdDispOut -> command.cmdDispatch
# command.cmdResponseIn -> genericHub.cmdRespIn
# ----------------------------------------------------------------------

@ Port for receiving events
Expand Down Expand Up @@ -183,6 +195,12 @@ module Svc {
@ bufferOut and bufferOutReturn ports must match
match bufferOut with bufferOutReturn

@ handling remote commands
output port cmdDispOut: [CmdDispatcherSequencePorts] Fw.Com

@ remote command response
sync input port cmdRespIn: [CmdDispatcherSequencePorts] Fw.CmdResponse

}

}
27 changes: 23 additions & 4 deletions Svc/GenericHub/GenericHub.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ class GenericHub final : public GenericHubComponentBase {
* Type of serialized data on the wire. Allows for expanding them on the opposing end.
*/
enum HubType {
HUB_TYPE_PORT, //!< Port type transmission
HUB_TYPE_BUFFER, //!< Buffer type transmission
HUB_TYPE_EVENT, //!< Event transmission
HUB_TYPE_CHANNEL, //!< Telemetry channel type
HUB_TYPE_PORT, //!< Port type transmission
HUB_TYPE_BUFFER, //!< Buffer type transmission
HUB_TYPE_EVENT, //!< Event transmission
HUB_TYPE_CHANNEL, //!< Telemetry channel type
HUB_TYPE_CMD_DISP, //!< Command dispatch type
HUB_TYPE_CMD_RESP, //!< Command response type
HUB_TYPE_MAX
};

Expand Down Expand Up @@ -62,6 +64,23 @@ class GenericHub final : public GenericHubComponentBase {
Fw::Buffer& fwBuffer //!< The buffer
) override;

//! Handler implementation for cmdDispIn
//!
//! Command buffer input port for sequencers or other sources of command buffers
void cmdDispIn_handler(FwIndexType portNum, //!< The port number
Fw::ComBuffer& data, //!< Buffer containing packet data
U32 context //!< Call context value; meaning chosen by user
) override;

//! Handler implementation for cmdRespIn
//!
//! Input port for command response
void cmdRespIn_handler(FwIndexType portNum, //!< The port number
FwOpcodeType opCode, //!< Command Op Code
U32 cmdSeq, //!< Command Sequence
const Fw::CmdResponse& response //!< The command response argument
) override;

//! Handler implementation for fromBufferDriver
//!
void fromBufferDriver_handler(const FwIndexType portNum, /*!< The port number*/
Expand Down
5 changes: 5 additions & 0 deletions Svc/GenericHub/test/ut/GenericHubTestMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ TEST(Nominal, TestTelemetry) {
tester.test_telemetry();
}

TEST(Nominal, TestCommands) {
Svc::GenericHubTester tester;
tester.test_commands();
}

int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down
44 changes: 44 additions & 0 deletions Svc/GenericHub/test/ut/GenericHubTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,38 @@ void GenericHubTester ::send_random_buffer(U32 port) {
m_buffer_in++;
}

void GenericHubTester ::test_command_dispatch() {
Fw::ComBuffer buffer;
clearFromPortHistory();
random_fill(buffer, FW_TLM_BUFFER_MAX_SIZE);

invoke_to_cmdDispIn(0, buffer, 279);

// **must** return buffer
ASSERT_from_fromBufferDriverReturn_SIZE(1);
ASSERT_from_cmdDispOut_SIZE(1);
ASSERT_from_cmdDispOut(0, buffer, 279);
clearFromPortHistory();
}

void GenericHubTester ::test_command_response() {
FwOpcodeType opCode = 0x3A56BF8C;
U32 cmdSeq = 825;
Fw::CmdResponse response = Fw::CmdResponse::VALIDATION_ERROR;

invoke_to_cmdRespIn(0, opCode, cmdSeq, response);

ASSERT_from_cmdRespOut_SIZE(1);
ASSERT_from_cmdRespOut(0, 0x3A56BF8C, 825, Fw::CmdResponse::VALIDATION_ERROR);
clearFromPortHistory();
}

void GenericHubTester ::test_commands() {
this->test_command_dispatch();

this->test_command_response();
}

// ----------------------------------------------------------------------
// Handlers for typed from ports
// ----------------------------------------------------------------------
Expand Down Expand Up @@ -251,6 +283,12 @@ void GenericHubTester ::connectPorts() {
// tlmIn
this->connect_to_tlmIn(0, this->componentIn.get_tlmIn_InputPort(0));

// cmdDispIn
this->connect_to_cmdDispIn(0, this->componentIn.get_cmdDispIn_InputPort(0));

// cmdRespIn
this->connect_to_cmdRespIn(0, this->componentIn.get_cmdRespIn_InputPort(0));

// fromBufferDriver
this->connect_to_fromBufferDriver(0, this->componentOut.get_fromBufferDriver_InputPort(0));

Expand All @@ -265,6 +303,12 @@ void GenericHubTester ::connectPorts() {
// tlmOut
this->componentOut.set_tlmOut_OutputPort(0, this->get_from_tlmOut(0));

// cmdDispOut
this->componentOut.set_cmdDispOut_OutputPort(0, this->get_from_cmdDispOut(0));

// cmdRespOut
this->componentOut.set_cmdRespOut_OutputPort(0, this->get_from_cmdRespOut(0));

// toBufferDriver
this->componentIn.set_toBufferDriver_OutputPort(0, this->get_from_toBufferDriver(0));

Expand Down
8 changes: 8 additions & 0 deletions Svc/GenericHub/test/ut/GenericHubTester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class GenericHubTester : public GenericHubGTestBase {
//!
void test_events();

//! Test of commands in-out
//!
void test_commands();

private:
// ----------------------------------------------------------------------
// Handlers for typed from ports
Expand Down Expand Up @@ -125,6 +129,10 @@ class GenericHubTester : public GenericHubGTestBase {

void random_fill(Fw::SerializeBufferBase& buffer, U32 max_size);

void test_command_dispatch();

void test_command_response();

// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions Svc/GenericHub/test/ut/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,11 @@ For more details see buffer data transfer sequence diagram below

![Top Level Generic Hub](./img/buffer_data_transfer.svg)

### Scenario for Command-In/Command-Out Testing

![Top Level Generic Hub](./img/command_dispatch.svg)

### Scenario for Response-In/Response-Out Testing

![Top Level Generic Hub](./img/command_response.svg)

1 change: 1 addition & 0 deletions Svc/GenericHub/test/ut/img/command_dispatch.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Svc/GenericHub/test/ut/img/command_response.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading