added CFDPHandler (not working yet)
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
add_subdirectory(action)
|
||||
add_subdirectory(cfdp)
|
||||
add_subdirectory(container)
|
||||
add_subdirectory(controller)
|
||||
add_subdirectory(datapool)
|
||||
|
59
src/core/cfdp/CFDPHandler.cpp
Normal file
59
src/core/cfdp/CFDPHandler.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include "fsfw/cfdp/CFDPHandler.h"
|
||||
|
||||
#include "fsfw/tmtcservices/AcceptsTelemetryIF.h"
|
||||
#include "fsfw/ipc/QueueFactory.h"
|
||||
#include "fsfw/objectmanager/ObjectManager.h"
|
||||
|
||||
object_id_t CFDPHandler::packetSource = 0;
|
||||
object_id_t CFDPHandler::packetDestination = 0;
|
||||
|
||||
CFDPHandler::CFDPHandler(object_id_t setObjectId, CFDPDistributor* dist) : SystemObject(setObjectId) {
|
||||
requestQueue = QueueFactory::instance()->createMessageQueue(CFDP_HANDLER_MAX_RECEPTION);
|
||||
distributor = dist;
|
||||
}
|
||||
|
||||
CFDPHandler::~CFDPHandler() {}
|
||||
|
||||
ReturnValue_t CFDPHandler::initialize() {
|
||||
ReturnValue_t result = SystemObject::initialize();
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
this->distributor->registerHandler(this);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t CFDPHandler::handleRequest(uint8_t subservice) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::debug << "CFDPHandler::handleRequest" << std::endl;
|
||||
#else
|
||||
sif::printDebug("CFDPHandler::handleRequest");
|
||||
#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t CFDPHandler::performOperation(uint8_t opCode) {
|
||||
ReturnValue_t result = this->performService();
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t CFDPHandler::performService() {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::debug << "CFDPHandler::performService" << std::endl;
|
||||
#else
|
||||
sif::printDebug("CFDPHandler::performService");
|
||||
#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
uint16_t CFDPHandler::getIdentifier() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
MessageQueueId_t CFDPHandler::getRequestQueue() {
|
||||
return this->requestQueue->getId();
|
||||
}
|
4
src/core/cfdp/CMakeLists.txt
Normal file
4
src/core/cfdp/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
||||
target_sources(${LIB_FSFW_NAME}
|
||||
PRIVATE
|
||||
CFDPHandler.cpp
|
||||
)
|
@ -1,15 +1,18 @@
|
||||
#include "fsfw/tcdistribution/CCSDSDistributorIF.h"
|
||||
#include "fsfw/tcdistribution/CFDPDistributor.h"
|
||||
|
||||
#include "fsfw/tmtcpacket/cfdp/CFDPPacketStored.h"
|
||||
|
||||
#include "fsfw/objectmanager/ObjectManager.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
|
||||
#define CFDP_DISTRIBUTOR_DEBUGGING 0
|
||||
|
||||
CFDPDistributor::CFDPDistributor(uint16_t setApid, object_id_t setObjectId,
|
||||
object_id_t setPacketSource) :
|
||||
TcDistributor(setObjectId), checker(setApid), verifyChannel(),
|
||||
tcStatus(RETURN_FAILED), packetSource(setPacketSource) {}
|
||||
TcDistributor(setObjectId),
|
||||
tcStatus(RETURN_FAILED), packetSource(setPacketSource) {
|
||||
this->apid = setApid;
|
||||
}
|
||||
|
||||
CFDPDistributor::~CFDPDistributor() {}
|
||||
|
||||
@ -30,20 +33,7 @@ CFDPDistributor::TcMqMapIter CFDPDistributor::selectDestination() {
|
||||
}
|
||||
this->currentPacket->setStoreAddress(this->currentMessage.getStorageId());
|
||||
if (currentPacket->getWholeData() != nullptr) {
|
||||
tcStatus = checker.checkPacket(currentPacket);
|
||||
if(tcStatus != HasReturnvaluesIF::RETURN_OK) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::debug << "CFDPDistributor::handlePacket: Packet format invalid, code " <<
|
||||
static_cast<int>(tcStatus) << std::endl;
|
||||
#else
|
||||
sif::printDebug("CFDPDistributor::handlePacket: Packet format invalid, code %d\n",
|
||||
static_cast<int>(tcStatus));
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
uint32_t queue_id = currentPacket->getService();
|
||||
queueMapIt = this->queueMap.find(queue_id);
|
||||
queueMapIt = this->queueMap.find(0);
|
||||
}
|
||||
else {
|
||||
tcStatus = PACKET_LOST;
|
||||
@ -70,24 +60,24 @@ CFDPDistributor::TcMqMapIter CFDPDistributor::selectDestination() {
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t CFDPDistributor::registerService(AcceptsTelecommandsIF* service) {
|
||||
uint16_t serviceId = service->getIdentifier();
|
||||
ReturnValue_t CFDPDistributor::registerHandler(AcceptsTelecommandsIF* handler) {
|
||||
uint16_t handlerId = handler->getIdentifier(); //should be 0, because CFDPHandler does not set a set a service-ID
|
||||
#if CFDP_DISTRIBUTOR_DEBUGGING == 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "Service ID: " << static_cast<int>(serviceId) << std::endl;
|
||||
sif::info << "CFDPDistributor::registerHandler: Handler ID: " << static_cast<int>(handlerId) << std::endl;
|
||||
#else
|
||||
sif::printInfo("Service ID: %d\n", static_cast<int>(serviceId));
|
||||
sif::printInfo("CFDPDistributor::registerHandler: Handler ID: %d\n", static_cast<int>(handlerId));
|
||||
#endif
|
||||
#endif
|
||||
MessageQueueId_t queue = service->getRequestQueue();
|
||||
auto returnPair = queueMap.emplace(serviceId, queue);
|
||||
MessageQueueId_t queue = handler->getRequestQueue();
|
||||
auto returnPair = queueMap.emplace(handlerId, queue);
|
||||
if (not returnPair.second) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "CFDPDistributor::registerService: Service ID already"
|
||||
sif::error << "CFDPDistributor::registerHandler: Service ID already"
|
||||
" exists in map" << std::endl;
|
||||
#else
|
||||
sif::printError("CFDPDistributor::registerService: Service ID already exists in map\n");
|
||||
sif::printError("CFDPDistributor::registerHandler: Service ID already exists in map\n");
|
||||
#endif
|
||||
#endif
|
||||
return SERVICE_ID_ALREADY_EXISTS;
|
||||
@ -99,30 +89,30 @@ MessageQueueId_t CFDPDistributor::getRequestQueue() {
|
||||
return tcQueue->getId();
|
||||
}
|
||||
|
||||
ReturnValue_t CFDPDistributor::callbackAfterSending(ReturnValue_t queueStatus) {
|
||||
if (queueStatus != RETURN_OK) {
|
||||
tcStatus = queueStatus;
|
||||
}
|
||||
if (tcStatus != RETURN_OK) {
|
||||
this->verifyChannel.sendFailureReport(tc_verification::ACCEPTANCE_FAILURE,
|
||||
currentPacket, tcStatus);
|
||||
// A failed packet is deleted immediately after reporting,
|
||||
// otherwise it will block memory.
|
||||
currentPacket->deletePacket();
|
||||
return RETURN_FAILED;
|
||||
} else {
|
||||
this->verifyChannel.sendSuccessReport(tc_verification::ACCEPTANCE_SUCCESS,
|
||||
currentPacket);
|
||||
return RETURN_OK;
|
||||
}
|
||||
}
|
||||
//ReturnValue_t CFDPDistributor::callbackAfterSending(ReturnValue_t queueStatus) {
|
||||
// if (queueStatus != RETURN_OK) {
|
||||
// tcStatus = queueStatus;
|
||||
// }
|
||||
// if (tcStatus != RETURN_OK) {
|
||||
// this->verifyChannel.sendFailureReport(tc_verification::ACCEPTANCE_FAILURE,
|
||||
// currentPacket, tcStatus);
|
||||
// // A failed packet is deleted immediately after reporting,
|
||||
// // otherwise it will block memory.
|
||||
// currentPacket->deletePacket();
|
||||
// return RETURN_FAILED;
|
||||
// } else {
|
||||
// this->verifyChannel.sendSuccessReport(tc_verification::ACCEPTANCE_SUCCESS,
|
||||
// currentPacket);
|
||||
// return RETURN_OK;
|
||||
// }
|
||||
//}
|
||||
|
||||
uint16_t CFDPDistributor::getIdentifier() {
|
||||
return checker.getApid();
|
||||
return this->apid;
|
||||
}
|
||||
|
||||
ReturnValue_t CFDPDistributor::initialize() {
|
||||
currentPacket = new TcPacketStoredPus();
|
||||
currentPacket = new CFDPPacketStored();
|
||||
if(currentPacket == nullptr) {
|
||||
// Should not happen, memory allocation failed!
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
|
@ -3,5 +3,6 @@ target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
SpacePacketBase.cpp
|
||||
)
|
||||
|
||||
add_subdirectory(cfdp)
|
||||
add_subdirectory(packetmatcher)
|
||||
add_subdirectory(pus)
|
20
src/core/tmtcpacket/cfdp/CFDPPacket.cpp
Normal file
20
src/core/tmtcpacket/cfdp/CFDPPacket.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include "fsfw/tmtcpacket/cfdp/CFDPPacket.h"
|
||||
|
||||
#include "fsfw/globalfunctions/CRC.h"
|
||||
#include "fsfw/globalfunctions/arrayprinter.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
CFDPPacket::CFDPPacket(const uint8_t* setData): SpacePacketBase(setData) {}
|
||||
|
||||
CFDPPacket::~CFDPPacket() {}
|
||||
|
||||
void CFDPPacket::print() {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "CFDPPacket::print:" << std::endl;
|
||||
#else
|
||||
sif::printInfo("CFDPPacket::print:\n");
|
||||
#endif
|
||||
arrayprinter::print(getWholeData(), getFullSize());
|
||||
}
|
85
src/core/tmtcpacket/cfdp/CFDPPacketStored.cpp
Normal file
85
src/core/tmtcpacket/cfdp/CFDPPacketStored.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
#include "fsfw/tmtcpacket/cfdp/CFDPPacketStored.h"
|
||||
#include "fsfw/objectmanager/ObjectManager.h"
|
||||
|
||||
StorageManagerIF* CFDPPacketStored::store = nullptr;
|
||||
|
||||
CFDPPacketStored::CFDPPacketStored(): CFDPPacket(nullptr) {
|
||||
}
|
||||
|
||||
CFDPPacketStored::CFDPPacketStored(store_address_t setAddress): CFDPPacket(nullptr) {
|
||||
this->setStoreAddress(setAddress);
|
||||
}
|
||||
|
||||
CFDPPacketStored::CFDPPacketStored(const uint8_t* data, size_t size): CFDPPacket(data) {
|
||||
if (this->getFullSize() != size) {
|
||||
return;
|
||||
}
|
||||
if (this->checkAndSetStore()) {
|
||||
ReturnValue_t status = store->addData(&storeAddress, data, size);
|
||||
if (status != HasReturnvaluesIF::RETURN_OK) {
|
||||
this->setData(nullptr);
|
||||
}
|
||||
const uint8_t* storePtr = nullptr;
|
||||
// Repoint base data pointer to the data in the store.
|
||||
store->getData(storeAddress, &storePtr, &size);
|
||||
this->setData(storePtr);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t CFDPPacketStored::deletePacket() {
|
||||
ReturnValue_t result = this->store->deleteData(this->storeAddress);
|
||||
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
this->setData(nullptr);
|
||||
return result;
|
||||
}
|
||||
|
||||
//CFDPPacket* CFDPPacketStored::getPacketBase() {
|
||||
// return this;
|
||||
//}
|
||||
void CFDPPacketStored::setStoreAddress(store_address_t setAddress) {
|
||||
this->storeAddress = setAddress;
|
||||
const uint8_t* tempData = nullptr;
|
||||
size_t tempSize;
|
||||
ReturnValue_t status = StorageManagerIF::RETURN_FAILED;
|
||||
if (this->checkAndSetStore()) {
|
||||
status = this->store->getData(this->storeAddress, &tempData, &tempSize);
|
||||
}
|
||||
if (status == StorageManagerIF::RETURN_OK) {
|
||||
this->setData(tempData);
|
||||
}
|
||||
else {
|
||||
this->setData(nullptr);
|
||||
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
}
|
||||
}
|
||||
|
||||
store_address_t CFDPPacketStored::getStoreAddress() {
|
||||
return this->storeAddress;
|
||||
}
|
||||
|
||||
bool CFDPPacketStored::checkAndSetStore() {
|
||||
if (this->store == nullptr) {
|
||||
this->store = ObjectManager::instance()->get<StorageManagerIF>(objects::TC_STORE);
|
||||
if (this->store == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "CFDPPacketStored::CFDPPacketStored: TC Store not found!"
|
||||
<< std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CFDPPacketStored::isSizeCorrect() {
|
||||
const uint8_t* temp_data = nullptr;
|
||||
size_t temp_size;
|
||||
ReturnValue_t status = this->store->getData(this->storeAddress, &temp_data,
|
||||
&temp_size);
|
||||
if (status == StorageManagerIF::RETURN_OK) {
|
||||
if (this->getFullSize() == temp_size) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
4
src/core/tmtcpacket/cfdp/CMakeLists.txt
Normal file
4
src/core/tmtcpacket/cfdp/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
CFDPPacket.cpp
|
||||
CFDPPacketStored.cpp
|
||||
)
|
Reference in New Issue
Block a user