Skip to content

Commit

Permalink
More routing
Browse files Browse the repository at this point in the history
  • Loading branch information
Reg Marr committed Nov 15, 2024
1 parent cce5125 commit a3bd393
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 35 deletions.
65 changes: 36 additions & 29 deletions FlightComputer/CCSDSTester/CCSDSTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
#include "Drv/Ip/IpSocket.hpp"
#include "FpConfig.h"
#include "FpConfig.hpp"
#include "Fw/Buffer/Buffer.hpp"
#include "Fw/Com/ComBuffer.hpp"
#include "Fw/Com/ComPacket.hpp"
#include "Fw/Logger/Logger.hpp"
#include "Fw/Types/Assert.hpp"
#include "Fw/Types/Serializable.hpp"
#include "Svc/FrameAccumulator/FrameDetector.hpp"
#include "Svc/FrameAccumulator/FrameDetector/CCSDSFrameDetector.hpp"
Expand Down Expand Up @@ -79,29 +81,28 @@ void CCSDSTester::seqCmdBuff_handler(NATIVE_INT_TYPE portNum,
}
Fw::Logger::log("\n");

// Send command response (success)
// this->cmdResponseIn_out(0, context, Fw::CmdResponse::OK);
FW_ASSERT(isConnected_bufferDeallocate_OutputPort(portNum));
Fw::Buffer buff(data.getBuffAddr(), data.getBuffCapacity());
bufferDeallocate_out(portNum, buff);
}

void CCSDSTester::bufferSendIn_handler(const NATIVE_INT_TYPE portNum,
Fw::Buffer &fwBuffer) {
Fw::Logger::log("Handling ccsds buffer");
// Pass through for now
this->bufferSendOut_out(0, fwBuffer);
Fw::Logger::log("Received File Buffer\n");
const FwSizeType size = fwBuffer.getSize();
U8 *ptr = fwBuffer.getData();
for (U32 i = 0; i < size; i++) {
if (i % 16 == 0) {
Fw::Logger::log("\n%04X: ", i);
}
Fw::Logger::log("%02X ", ptr[i]);
}
Fw::Logger::log("\n");

FW_ASSERT(isConnected_bufferDeallocate_OutputPort(portNum));
bufferDeallocate_out(portNum, fwBuffer);
}

// void CCSDSTester ::dataIn_handler(FwIndexType portNum, Fw::Buffer& buffer,
// const Drv::RecvStatus& status) {
// // Check whether there is data to process

// // Fw::Logger::log("FrameAccumulator often send");
// // if (status.e == Drv::RecvStatus::RECV_OK) {
// // // There is: process the data
// // this->processBuffer(buffer);
// // }
// // // Deallocate the buffer
// // this->dataDeallocate_out(0, buffer);
// }
void CCSDSTester::comStatusIn_handler(
FwIndexType portNum, //!< The port number
Fw::Success &condition //!< Condition success/failure
Expand All @@ -121,11 +122,12 @@ void CCSDSTester::PING_cmdHandler(const FwOpcodeType opCode, const U32 cmdSeq) {

U32 dfltMessage = 0x9944fead;
com.resetSer();
com.serialize(Fw::ComPacket::ComPacketType::FW_PACKET_COMMAND);
U8 packetType = Fw::ComPacket::ComPacketType::FW_PACKET_COMMAND;
com.serialize(packetType);
com.serialize(dfltMessage);

PktSend_out(0, com, 0);
cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
// cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
}
void CCSDSTester::MESSAGE_cmdHandler(const FwOpcodeType opCode,
const U32 cmdSeq,
Expand All @@ -137,22 +139,27 @@ void CCSDSTester::MESSAGE_cmdHandler(const FwOpcodeType opCode,
Fw::Logger::log("Not Ready");
}
Fw::ComBuffer com;
com.resetSer();
// U32 starter = 0xFFFF;
// com.serialize(starter);
// Fw::ComPacket::ComPacketType_t packetType = Fw::ComPacket::ComPacketType_e::FW_PACKET_FILE;
U8 packetType = Fw::ComPacket::ComPacketType::FW_PACKET_FILE;
com.serialize(packetType);
com.serialize(str1);

// TODO add support for checking the port's connected
PktSend_out(0, com, 0);

cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
// cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
}

Drv::SendStatus CCSDSTester::drvSend_handler(FwIndexType, Fw::Buffer & buffer) {
Drv::SendStatus CCSDSTester::drvSend_handler(FwIndexType portNum, Fw::Buffer & buffer) {

// Types::CircularBuffer circBoi(buffer.getData(), buffer.getSize());
// Fw::SerializeStatus stat = circBoi.serialize(buffer.getData(), buffer.getSize());
// circBoi.print();
// U8 btt = 0;
// circBoi.peek(btt, 0);
// Fw::Logger::log("circBoi %x %d alloc %d cap %d\n", btt, stat, circBoi.get_allocated_size(), circBoi.get_capacity());
Types::CircularBuffer circBoi(buffer.getData(), buffer.getSize());
Fw::SerializeStatus stat = circBoi.serialize(buffer.getData(), buffer.getSize());
circBoi.print();
U8 btt = 0;
circBoi.peek(btt, 0);
Fw::Logger::log("circBoi %x %d alloc %d cap %d\n", btt, stat, circBoi.get_allocated_size(), circBoi.get_capacity());

// Svc::FrameDetector::Status status = Svc::FrameDetector::Status::FRAME_DETECTED;
// Svc::FrameDetectors::TMSpaceDataLinkDetector ccsdsFrameDetector;
Expand All @@ -161,7 +168,7 @@ Drv::SendStatus CCSDSTester::drvSend_handler(FwIndexType, Fw::Buffer & buffer) {
// status = ccsdsFrameDetector.detect(circBoi, size_out);
// Fw::Logger::log("Status %d out %d\n", status, size_out);

if (!isConnected_drvRcv_OutputPort(0)) {
if (!isConnected_drvRcv_OutputPort(portNum)) {
return Drv::SendStatus::SEND_ERROR;
}

Expand Down
2 changes: 1 addition & 1 deletion FlightComputer/CCSDSTester/CCSDSTester.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ module FlightComputer {
# guarded input port $send: Drv.ByteStreamSend

# output port allocate: Fw.BufferGet
# output port deallocate: Fw.BufferSend
output port bufferDeallocate: Fw.BufferSend

@ Simple command received interface
async command PING
Expand Down
2 changes: 1 addition & 1 deletion FlightComputer/Top/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static void dfltSigHandler(int signum) {
int main(int argc, char* argv[]) {
Os::Console::init();
U32 uplink_port = 0; // Invalid port number forced
U32 downlink_port = 0; // Invalid port number forced
U32 downlink_port = 0; // Invalid port number forcedt
I32 option;
char* hostname;
option = 0;
Expand Down
2 changes: 1 addition & 1 deletion FlightComputer/Top/instances.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ module FlightComputer {
stack size Default.stackSize \
priority 59

instance sppDataLinkDeframer: Svc.SpaceDataLinkDeframer base id 0x5000
instance sppDataLinkDeframer: Svc.TMSpaceDataLinkDeframer base id 0x5000
instance ccsdsFramer: Svc.Framer base id 0x5100

# NOTE by getting the fprimeFrameAccumulator to use multiple frame dectors and multiple frameOut ports
Expand Down
2 changes: 2 additions & 0 deletions FlightComputer/Top/topology.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ module FlightComputer {
ccsdsFramer.framedAllocate -> commsBufferManager.bufferGetCallee
ccsdsFramer.framedOut -> ccsdsLink.comDataIn
ccsdsLink.comStatus -> ccsdsNode.comStatusIn
# ccsdsNode.allocate -> commsBufferManager.bufferGetCallee
ccsdsNode.drvReady -> ccsdsLink.drvConnected
ccsdsLink.drvDataOut -> ccsdsNode.drvSend
ccsdsNode.drvRcv -> ccsdsLink.drvDataIn
Expand All @@ -167,6 +168,7 @@ module FlightComputer {
ccsdsUplinkRouter.commandOut -> ccsdsNode.seqCmdBuff
ccsdsUplinkRouter.fileOut -> ccsdsNode.bufferSendIn
ccsdsUplinkRouter.bufferDeallocate -> commsBufferManager.bufferSendIn
ccsdsNode.bufferDeallocate -> commsBufferManager.bufferSendIn

ccsdsNode.seqCmdStatus -> ccsdsUplinkRouter.cmdResponseIn
}
Expand Down
13 changes: 11 additions & 2 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ Options:
--debug Enable debug mode
--as-host Run as host
--clean Clean build
--host-thread-ctl Set thread control for running without sudo (this itself requires sudo)
--help Show this help message
Commands:
docker-build Build the Docker image
build Build the project
inspect [container] Inspect a container
gds Run the GDS
exec gds Run the GDS
exec FlightComputer Run the Flight Software
update Pull latest Docker images
teardown Tear down the environment
EOF
Expand All @@ -44,6 +45,7 @@ CLEAN=0
AS_HOST=0
DAEMON=0
DEBUG=0
SET_THREAD_CTRL=0

# Process flags
for arg in "$@"; do
Expand All @@ -52,6 +54,7 @@ for arg in "$@"; do
--debug) DEBUG=1 ;;
--as-host) AS_HOST=1 ;;
--clean) CLEAN=1 ;;
--host-thread-ctrl) SET_THREAD_CTRL=1 ;;
--help) show_help; exit 0 ;;
esac
done
Expand Down Expand Up @@ -132,6 +135,12 @@ case $1 in
MOD_DICT_CMD="sed -i \"s|${FSW_WDIR}|${SCRIPT_DIR}|g\" \"${SCRIPT_DIR}/FlightComputer/build-fprime-automatic-native/compile_commands.json\""

exec_cmd "$MOD_DICT_CMD"

if [ "${SET_THREAD_CTRL}" -eq "1" ]; then
echo 'Setting thread control for non-sudo host execution'
THREAD_CMD="sudo setcap \"cap_sys_nice+ep\" ${SCRIPT_DIR}/FlightComputer/build-artifacts/Linux/FlightComputer/bin/FlightComputer"
exec_cmd "$THREAD_CMD"
fi
;;

"inspect")
Expand Down

0 comments on commit a3bd393

Please sign in to comment.