message arriving.
big clean up in tcdistribution folder
This commit is contained in:
parent
399fc0e287
commit
2efcda735f
@ -1,6 +1,7 @@
|
|||||||
#include <framework/osal/linux/TcUnixUdpPollingTask.h>
|
#include <framework/osal/linux/TcUnixUdpPollingTask.h>
|
||||||
|
#include <framework/globalfunctions/arrayprinter.h>
|
||||||
|
|
||||||
TcSocketPollingTask::TcSocketPollingTask(object_id_t objectId,
|
TcUnixUdpPollingTask::TcUnixUdpPollingTask(object_id_t objectId,
|
||||||
object_id_t tmtcUnixUdpBridge, size_t frameSize,
|
object_id_t tmtcUnixUdpBridge, size_t frameSize,
|
||||||
double timeoutSeconds): SystemObject(objectId),
|
double timeoutSeconds): SystemObject(objectId),
|
||||||
tmtcBridgeId(tmtcUnixUdpBridge) {
|
tmtcBridgeId(tmtcUnixUdpBridge) {
|
||||||
@ -23,23 +24,13 @@ TcSocketPollingTask::TcSocketPollingTask(object_id_t objectId,
|
|||||||
else {
|
else {
|
||||||
receptionTimeout = timevalOperations::toTimeval(timeoutSeconds);
|
receptionTimeout = timevalOperations::toTimeval(timeoutSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set receive timeout.
|
|
||||||
int result = setsockopt(serverUdpSocket, SOL_SOCKET, SO_RCVTIMEO,
|
|
||||||
&receptionTimeout, sizeof(receptionTimeout));
|
|
||||||
if(result == -1) {
|
|
||||||
sif::error << "TcSocketPollingTask::TcSocketPollingTask: Setting receive"
|
|
||||||
"timeout failed with " << strerror(errno) << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TcSocketPollingTask::~TcSocketPollingTask() {
|
TcUnixUdpPollingTask::~TcUnixUdpPollingTask() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t TcSocketPollingTask::performOperation(uint8_t opCode) {
|
ReturnValue_t TcUnixUdpPollingTask::performOperation(uint8_t opCode) {
|
||||||
// Poll for new data permanently. The call will block until the specified
|
// Poll for new UDP datagrams in permanent loop.
|
||||||
// length of bytes has been received or a timeout occured.
|
|
||||||
while(1) {
|
while(1) {
|
||||||
//! Sender Address is cached here.
|
//! Sender Address is cached here.
|
||||||
struct sockaddr_in senderAddress;
|
struct sockaddr_in senderAddress;
|
||||||
@ -51,18 +42,31 @@ ReturnValue_t TcSocketPollingTask::performOperation(uint8_t opCode) {
|
|||||||
// handle error
|
// handle error
|
||||||
sif::error << "TcSocketPollingTask::performOperation: recvfrom "
|
sif::error << "TcSocketPollingTask::performOperation: recvfrom "
|
||||||
"failed with " << strerror(errno) << std::endl;
|
"failed with " << strerror(errno) << std::endl;
|
||||||
|
if(errno == EAGAIN or errno == EWOULDBLOCK) {
|
||||||
|
sif::info << "timeout" << std::endl;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
sif::debug << "TcSocketPollingTask::performOperation: " << bytesReceived
|
sif::debug << "TcSocketPollingTask::performOperation: " << bytesReceived
|
||||||
<< " bytes received" << std::endl;
|
<< " bytes received" << std::endl;
|
||||||
|
|
||||||
ReturnValue_t result = handleSuccessfullTcRead();
|
ReturnValue_t result = handleSuccessfullTcRead(bytesReceived);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_FAILED) {
|
||||||
|
|
||||||
|
}
|
||||||
tmtcBridge->checkAndSetClientAddress(senderAddress);
|
tmtcBridge->checkAndSetClientAddress(senderAddress);
|
||||||
}
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t TcSocketPollingTask::initialize() {
|
ReturnValue_t TcUnixUdpPollingTask::initialize() {
|
||||||
|
tcStore = objectManager->get<StorageManagerIF>(objects::TC_STORE);
|
||||||
|
if (tcStore == nullptr) {
|
||||||
|
sif::error << "TcSerialPollingTask::initialize: TC Store uninitialized!"
|
||||||
|
<< std::endl;
|
||||||
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
tmtcBridge = objectManager->get<TmTcUnixUdpBridge>(tmtcBridgeId);
|
tmtcBridge = objectManager->get<TmTcUnixUdpBridge>(tmtcBridgeId);
|
||||||
if(tmtcBridge == nullptr) {
|
if(tmtcBridge == nullptr) {
|
||||||
sif::error << "TcSocketPollingTask::TcSocketPollingTask: Invalid"
|
sif::error << "TcSocketPollingTask::TcSocketPollingTask: Invalid"
|
||||||
@ -70,10 +74,41 @@ ReturnValue_t TcSocketPollingTask::initialize() {
|
|||||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
targetTcDestination = tmtcBridge->getReportReceptionQueue();
|
||||||
|
|
||||||
serverUdpSocket = tmtcBridge->serverSocket;
|
serverUdpSocket = tmtcBridge->serverSocket;
|
||||||
|
|
||||||
|
// Set receive timeout.
|
||||||
|
// int result = setsockopt(serverUdpSocket, SOL_SOCKET, SO_RCVTIMEO,
|
||||||
|
// &receptionTimeout, sizeof(receptionTimeout));
|
||||||
|
// if(result == -1) {
|
||||||
|
// sif::error << "TcSocketPollingTask::TcSocketPollingTask: Setting "
|
||||||
|
// "receive timeout failed with " << strerror(errno) << std::endl;
|
||||||
|
// return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||||
|
// }
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t TcSocketPollingTask::handleSuccessfullTcRead() {
|
ReturnValue_t TcUnixUdpPollingTask::handleSuccessfullTcRead(size_t bytesRead) {
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
store_address_t storeId = 0;
|
||||||
|
ReturnValue_t result = tcStore->addData(&storeId,
|
||||||
|
receptionBuffer.data(), bytesRead);
|
||||||
|
// arrayprinter::print(receptionBuffer.data(), bytesRead);
|
||||||
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
sif::debug << "TcSerialPollingTask::transferPusToSoftwareBus: Data "
|
||||||
|
"storage failed" << std::endl;
|
||||||
|
sif::debug << "Packet size: " << bytesRead << std::endl;
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TmTcMessage message(storeId);
|
||||||
|
result = MessageQueueSenderIF::sendMessage(targetTcDestination, &message);
|
||||||
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
sif::error << "Serial Polling: Sending message to queue failed"
|
||||||
|
<< std::endl;
|
||||||
|
tcStore->deleteData(storeId);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#ifndef FRAMEWORK_OSAL_LINUX_TCSOCKETPOLLINGTASK_H_
|
#ifndef FRAMEWORK_OSAL_LINUX_TCSOCKETPOLLINGTASK_H_
|
||||||
#define FRAMEWORK_OSAL_LINUX_TCSOCKETPOLLINGTASK_H_
|
#define FRAMEWORK_OSAL_LINUX_TCSOCKETPOLLINGTASK_H_
|
||||||
|
|
||||||
#include <framework/objectmanager/SystemObject.h>
|
#include <framework/objectmanager/SystemObject.h>
|
||||||
#include <framework/osal/linux/TmTcUnixUdpBridge.h>
|
#include <framework/osal/linux/TmTcUnixUdpBridge.h>
|
||||||
#include <framework/tasks/ExecutableObjectIF.h>
|
#include <framework/tasks/ExecutableObjectIF.h>
|
||||||
@ -16,7 +17,7 @@
|
|||||||
* This class caches the IP address of the sender. It is assumed there
|
* This class caches the IP address of the sender. It is assumed there
|
||||||
* is only one sender for now.
|
* is only one sender for now.
|
||||||
*/
|
*/
|
||||||
class TcSocketPollingTask: public SystemObject,
|
class TcUnixUdpPollingTask: public SystemObject,
|
||||||
public ExecutableObjectIF {
|
public ExecutableObjectIF {
|
||||||
friend class TmTcUnixUdpBridge;
|
friend class TmTcUnixUdpBridge;
|
||||||
public:
|
public:
|
||||||
@ -24,17 +25,21 @@ public:
|
|||||||
//! 0.5 default milliseconds timeout for now.
|
//! 0.5 default milliseconds timeout for now.
|
||||||
static constexpr timeval DEFAULT_TIMEOUT = {.tv_sec = 0, .tv_usec = 500};
|
static constexpr timeval DEFAULT_TIMEOUT = {.tv_sec = 0, .tv_usec = 500};
|
||||||
|
|
||||||
TcSocketPollingTask(object_id_t objectId, object_id_t tmtcUnixUdpBridge,
|
TcUnixUdpPollingTask(object_id_t objectId, object_id_t tmtcUnixUdpBridge,
|
||||||
size_t frameSize = 0, double timeoutSeconds = -1);
|
size_t frameSize = 0, double timeoutSeconds = -1);
|
||||||
virtual~ TcSocketPollingTask();
|
virtual~ TcUnixUdpPollingTask();
|
||||||
|
|
||||||
virtual ReturnValue_t performOperation(uint8_t opCode) override;
|
virtual ReturnValue_t performOperation(uint8_t opCode) override;
|
||||||
virtual ReturnValue_t initialize() override;
|
virtual ReturnValue_t initialize() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
StorageManagerIF* tcStore = nullptr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! TMTC bridge is cached.
|
//! TMTC bridge is cached.
|
||||||
object_id_t tmtcBridgeId = objects::NO_OBJECT;
|
object_id_t tmtcBridgeId = objects::NO_OBJECT;
|
||||||
TmTcUnixUdpBridge* tmtcBridge = nullptr;
|
TmTcUnixUdpBridge* tmtcBridge = nullptr;
|
||||||
|
MessageQueueId_t targetTcDestination = MessageQueueIF::NO_QUEUE;
|
||||||
//! Reception flags: https://linux.die.net/man/2/recvfrom.
|
//! Reception flags: https://linux.die.net/man/2/recvfrom.
|
||||||
int receptionFlags = 0;
|
int receptionFlags = 0;
|
||||||
|
|
||||||
@ -47,7 +52,7 @@ private:
|
|||||||
size_t frameSize = 0;
|
size_t frameSize = 0;
|
||||||
timeval receptionTimeout;
|
timeval receptionTimeout;
|
||||||
|
|
||||||
ReturnValue_t handleSuccessfullTcRead();
|
ReturnValue_t handleSuccessfullTcRead(size_t bytesRead);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ void TmTcUnixUdpBridge::checkAndSetClientAddress(sockaddr_in newAddress) {
|
|||||||
void TmTcUnixUdpBridge::handleBindError() {
|
void TmTcUnixUdpBridge::handleBindError() {
|
||||||
// See: https://man7.org/linux/man-pages/man2/bind.2.html
|
// See: https://man7.org/linux/man-pages/man2/bind.2.html
|
||||||
switch(errno) {
|
switch(errno) {
|
||||||
case(EACCES):
|
case(EACCES): {
|
||||||
/*
|
/*
|
||||||
Ephermeral ports can be shown with following command:
|
Ephermeral ports can be shown with following command:
|
||||||
sysctl -A | grep ip_local_port_range
|
sysctl -A | grep ip_local_port_range
|
||||||
@ -110,6 +110,7 @@ void TmTcUnixUdpBridge::handleBindError() {
|
|||||||
"Ports 1-1024 are reserved on UNIX systems and require root "
|
"Ports 1-1024 are reserved on UNIX systems and require root "
|
||||||
"rights while ephermeral ports should not be used as well."
|
"rights while ephermeral ports should not be used as well."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case(EADDRINUSE):
|
case(EADDRINUSE):
|
||||||
case(EBADF):
|
case(EBADF):
|
||||||
@ -122,16 +123,18 @@ void TmTcUnixUdpBridge::handleBindError() {
|
|||||||
case(ENOENT):
|
case(ENOENT):
|
||||||
case(ENOMEM):
|
case(ENOMEM):
|
||||||
case(ENOTDIR):
|
case(ENOTDIR):
|
||||||
case(EROFS):
|
case(EROFS): {
|
||||||
sif::error << "TmTcUnixBridge::TmTcUnixBridge: Socket creation failed"
|
sif::error << "TmTcUnixBridge::TmTcUnixBridge: Socket creation failed"
|
||||||
<< " with " << strerror(errno) << std::endl;
|
<< " with " << strerror(errno) << std::endl;
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
|
default: {
|
||||||
sif::error << "TmTcUnixBridge::TmTcUnixBridge: Unknown error"
|
sif::error << "TmTcUnixBridge::TmTcUnixBridge: Unknown error"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ReturnValue_t TmTcUnixUdpBridge::receiveTc(uint8_t **recvBuffer, size_t *size) {
|
ReturnValue_t TmTcUnixUdpBridge::receiveTc(uint8_t **recvBuffer, size_t *size) {
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include <netinet/udp.h>
|
#include <netinet/udp.h>
|
||||||
|
|
||||||
class TmTcUnixUdpBridge: public TmTcBridge {
|
class TmTcUnixUdpBridge: public TmTcBridge {
|
||||||
friend class TcSocketPollingTask;
|
friend class TcUnixUdpPollingTask;
|
||||||
public:
|
public:
|
||||||
// The ports chosen here should not be used by any other process.
|
// The ports chosen here should not be used by any other process.
|
||||||
// List of used ports on Linux: /etc/services
|
// List of used ports on Linux: /etc/services
|
||||||
|
@ -2,30 +2,37 @@
|
|||||||
#include <framework/tcdistribution/CCSDSDistributor.h>
|
#include <framework/tcdistribution/CCSDSDistributor.h>
|
||||||
#include <framework/tmtcpacket/SpacePacketBase.h>
|
#include <framework/tmtcpacket/SpacePacketBase.h>
|
||||||
|
|
||||||
CCSDSDistributor::CCSDSDistributor( uint16_t setDefaultApid, object_id_t setObjectId ) :
|
CCSDSDistributor::CCSDSDistributor(uint16_t setDefaultApid,
|
||||||
TcDistributor( setObjectId ), default_apid( setDefaultApid ), tcStore(NULL) {
|
object_id_t setObjectId):
|
||||||
|
TcDistributor(setObjectId), defaultApid( setDefaultApid ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CCSDSDistributor::~CCSDSDistributor() {
|
CCSDSDistributor::~CCSDSDistributor() {}
|
||||||
|
|
||||||
}
|
TcDistributor::TcMessageQueueMapIter CCSDSDistributor::selectDestination() {
|
||||||
|
// sif::debug << "CCSDSDistributor::selectDestination received: " <<
|
||||||
iterator_t CCSDSDistributor::selectDestination() {
|
// this->currentMessage.getStorageId().pool_index << ", " <<
|
||||||
// debug << "CCSDSDistributor::selectDestination received: " << this->currentMessage.getStorageId().pool_index << ", " << this->currentMessage.getStorageId().packet_index << std::endl;
|
// this->currentMessage.getStorageId().packet_index << std::endl;
|
||||||
const uint8_t* p_packet = NULL;
|
const uint8_t* packet = nullptr;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
//TODO check returncode?
|
ReturnValue_t result = this->tcStore->getData(currentMessage.getStorageId(),
|
||||||
this->tcStore->getData( this->currentMessage.getStorageId(), &p_packet, &size );
|
&packet, &size );
|
||||||
SpacePacketBase current_packet( p_packet );
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
// info << "CCSDSDistributor::selectDestination has packet with APID " << std::hex << current_packet.getAPID() << std::dec << std::endl;
|
sif::error << "CCSDSDistributor::selectDestination: Getting data from"
|
||||||
iterator_t position = this->queueMap.find( current_packet.getAPID() );
|
"store failed!" << std::endl;
|
||||||
|
}
|
||||||
|
SpacePacketBase currentPacket(packet);
|
||||||
|
|
||||||
|
// sif:: info << "CCSDSDistributor::selectDestination has packet with APID "
|
||||||
|
// << std::hex << currentPacket.getAPID() << std::dec << std::endl;
|
||||||
|
TcMessageQueueMapIter position = this->queueMap.find(currentPacket.getAPID());
|
||||||
if ( position != this->queueMap.end() ) {
|
if ( position != this->queueMap.end() ) {
|
||||||
return position;
|
return position;
|
||||||
} else {
|
} else {
|
||||||
//The APID was not found. Forward packet to main SW-APID anyway to create acceptance failure report.
|
//The APID was not found. Forward packet to main SW-APID anyway to
|
||||||
return this->queueMap.find( this->default_apid );
|
// create acceptance failure report.
|
||||||
|
return this->queueMap.find( this->defaultApid );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageQueueId_t CCSDSDistributor::getRequestQueue() {
|
MessageQueueId_t CCSDSDistributor::getRequestQueue() {
|
||||||
|
@ -1,58 +1,69 @@
|
|||||||
#ifndef CCSDSDISTRIBUTOR_H_
|
#ifndef FRAMEWORK_TCDISTRIBUTION_CCSDSDISTRIBUTOR_H_
|
||||||
#define CCSDSDISTRIBUTOR_H_
|
#define FRAMEWORK_TCDISTRIBUTION_CCSDSDISTRIBUTOR_H_
|
||||||
|
|
||||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||||
#include <framework/storagemanager/StorageManagerIF.h>
|
#include <framework/storagemanager/StorageManagerIF.h>
|
||||||
#include <framework/tcdistribution/CCSDSDistributorIF.h>
|
#include <framework/tcdistribution/CCSDSDistributorIF.h>
|
||||||
#include <framework/tcdistribution/TcDistributor.h>
|
#include <framework/tcdistribution/TcDistributor.h>
|
||||||
#include <framework/tmtcservices/AcceptsTelecommandsIF.h>
|
#include <framework/tmtcservices/AcceptsTelecommandsIF.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An instantiation of the CCSDSDistributorIF.
|
* @brief An instantiation of the CCSDSDistributorIF.
|
||||||
* It receives Space Packets, and selects a destination depending on the APID of the telecommands.
|
* @details
|
||||||
|
* It receives Space Packets, and selects a destination depending on the
|
||||||
|
* APID of the telecommands.
|
||||||
* The Secondary Header (with Service/Subservice) is ignored.
|
* The Secondary Header (with Service/Subservice) is ignored.
|
||||||
* \ingroup tc_distribution
|
* @ingroup tc_distribution
|
||||||
*/
|
*/
|
||||||
class CCSDSDistributor : public TcDistributor, public CCSDSDistributorIF, public AcceptsTelecommandsIF {
|
class CCSDSDistributor : public TcDistributor,
|
||||||
protected:
|
public CCSDSDistributorIF,
|
||||||
/**
|
public AcceptsTelecommandsIF {
|
||||||
* This implementation checks if an Application with fitting APID has registered and forwards the
|
|
||||||
* packet to the according message queue.
|
|
||||||
* If the packet is not found, it returns the queue to \c default_apid, where a Acceptance Failure
|
|
||||||
* message should be generated.
|
|
||||||
* @return Iterator to map entry of found APID or iterator to default APID.
|
|
||||||
*/
|
|
||||||
iterator_t selectDestination();
|
|
||||||
/**
|
|
||||||
* The default APID, where packets with unknown APID are sent to.
|
|
||||||
*/
|
|
||||||
uint16_t default_apid;
|
|
||||||
/**
|
|
||||||
* A reference to the TC storage must be maintained, as this class handles pure Space Packets and there
|
|
||||||
* exists no SpacePacketStored class.
|
|
||||||
*/
|
|
||||||
StorageManagerIF* tcStore;
|
|
||||||
/**
|
|
||||||
* The callback here handles the generation of acceptance success/failure messages.
|
|
||||||
*/
|
|
||||||
ReturnValue_t callbackAfterSending( ReturnValue_t queueStatus );
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* The constructor sets the default APID and calls the TcDistributor ctor with a certain object id.
|
* @brief The constructor sets the default APID and calls the
|
||||||
* \c tcStore is set in the \c initialize method.
|
* TcDistributor ctor with a certain object id.
|
||||||
* @param set_default_apid The default APID, where packets with unknown destination are sent to.
|
* @details
|
||||||
|
* @c tcStore is set in the @c initialize method.
|
||||||
|
* @param set_default_apid The default APID, where packets with unknown
|
||||||
|
* destination are sent to.
|
||||||
*/
|
*/
|
||||||
CCSDSDistributor( uint16_t setDefaultApid, object_id_t setObjectId );
|
CCSDSDistributor( uint16_t setDefaultApid, object_id_t setObjectId );
|
||||||
/**
|
/**
|
||||||
* The destructor is empty.
|
* The destructor is empty.
|
||||||
*/
|
*/
|
||||||
~CCSDSDistributor();
|
~CCSDSDistributor();
|
||||||
MessageQueueId_t getRequestQueue();
|
|
||||||
ReturnValue_t registerApplication( uint16_t apid, MessageQueueId_t id );
|
MessageQueueId_t getRequestQueue() override;
|
||||||
ReturnValue_t registerApplication( AcceptsTelecommandsIF* application );
|
ReturnValue_t registerApplication( uint16_t apid,
|
||||||
|
MessageQueueId_t id) override;
|
||||||
|
ReturnValue_t registerApplication(
|
||||||
|
AcceptsTelecommandsIF* application) override;
|
||||||
uint16_t getIdentifier();
|
uint16_t getIdentifier();
|
||||||
ReturnValue_t initialize();
|
ReturnValue_t initialize() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* This implementation checks if an application with fitting APID has
|
||||||
|
* registered and forwards the packet to the according message queue.
|
||||||
|
* If the packet is not found, it returns the queue to @c defaultApid,
|
||||||
|
* where a Acceptance Failure message should be generated.
|
||||||
|
* @return Iterator to map entry of found APID or iterator to default APID.
|
||||||
|
*/
|
||||||
|
TcMessageQueueMapIter selectDestination();
|
||||||
|
/**
|
||||||
|
* The default APID, where packets with unknown APID are sent to.
|
||||||
|
*/
|
||||||
|
uint16_t defaultApid;
|
||||||
|
/**
|
||||||
|
* A reference to the TC storage must be maintained, as this class handles
|
||||||
|
* pure Space Packets and there exists no SpacePacketStored class.
|
||||||
|
*/
|
||||||
|
StorageManagerIF* tcStore = nullptr;
|
||||||
|
/**
|
||||||
|
* The callback here handles the generation of acceptance
|
||||||
|
* success/failure messages.
|
||||||
|
*/
|
||||||
|
ReturnValue_t callbackAfterSending( ReturnValue_t queueStatus );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /* FRAMEWORK_TCDISTRIBUTION_CCSDSDISTRIBUTOR_H_ */
|
||||||
|
|
||||||
#endif /* CCSDSDISTRIBUTOR_H_ */
|
|
||||||
|
@ -12,9 +12,9 @@ PUSDistributor::PUSDistributor(uint16_t setApid, object_id_t setObjectId,
|
|||||||
|
|
||||||
PUSDistributor::~PUSDistributor() {}
|
PUSDistributor::~PUSDistributor() {}
|
||||||
|
|
||||||
iterator_t PUSDistributor::selectDestination() {
|
TcDistributor::TcMessageQueueMapIter PUSDistributor::selectDestination() {
|
||||||
// debug << "PUSDistributor::handlePacket received: " << this->current_packet_id.store_index << ", " << this->current_packet_id.packet_index << std::endl;
|
// debug << "PUSDistributor::handlePacket received: " << this->current_packet_id.store_index << ", " << this->current_packet_id.packet_index << std::endl;
|
||||||
iterator_t queueMapIt = this->queueMap.end();
|
TcMessageQueueMapIter queueMapIt = this->queueMap.end();
|
||||||
this->currentPacket.setStoreAddress(this->currentMessage.getStorageId());
|
this->currentPacket.setStoreAddress(this->currentMessage.getStorageId());
|
||||||
if (currentPacket.getWholeData() != NULL) {
|
if (currentPacket.getWholeData() != NULL) {
|
||||||
tcStatus = checker.checkPacket(¤tPacket);
|
tcStatus = checker.checkPacket(¤tPacket);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef PUSDISTRIBUTOR_H_
|
#ifndef FRAMEWORK_TCDISTRIBUTION_PUSDISTRIBUTOR_H_
|
||||||
#define PUSDISTRIBUTOR_H_
|
#define FRAMEWORK_TCDISTRIBUTION_PUSDISTRIBUTOR_H_
|
||||||
|
|
||||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||||
#include <framework/tcdistribution/PUSDistributorIF.h>
|
#include <framework/tcdistribution/PUSDistributorIF.h>
|
||||||
@ -9,37 +9,42 @@
|
|||||||
#include <framework/tmtcservices/VerificationReporter.h>
|
#include <framework/tmtcservices/VerificationReporter.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class accepts PUS Telecommands and forwards them to Application services.
|
* This class accepts PUS Telecommands and forwards them to Application
|
||||||
* In addition, the class performs a formal packet check and sends acceptance success
|
* services. In addition, the class performs a formal packet check and
|
||||||
* or failure messages.
|
* sends acceptance success or failure messages.
|
||||||
* \ingroup tc_distribution
|
* @ingroup tc_distribution
|
||||||
*/
|
*/
|
||||||
class PUSDistributor: public TcDistributor,
|
class PUSDistributor: public TcDistributor,
|
||||||
public PUSDistributorIF,
|
public PUSDistributorIF,
|
||||||
public AcceptsTelecommandsIF {
|
public AcceptsTelecommandsIF {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* The ctor passes \c set_apid to the checker class and calls the TcDistribution ctor with a certain object id.
|
* The ctor passes @c set_apid to the checker class and calls the
|
||||||
|
* TcDistribution ctor with a certain object id.
|
||||||
* @param setApid The APID of this receiving Application.
|
* @param setApid The APID of this receiving Application.
|
||||||
* @param setObjectId Object ID of the distributor itself
|
* @param setObjectId Object ID of the distributor itself
|
||||||
* @param setPacketSource Object ID of the source of TC packets. Must implement CCSDSDistributorIF.
|
* @param setPacketSource Object ID of the source of TC packets.
|
||||||
|
* Must implement CCSDSDistributorIF.
|
||||||
*/
|
*/
|
||||||
PUSDistributor(uint16_t setApid, object_id_t setObjectId, object_id_t setPacketSource);
|
PUSDistributor(uint16_t setApid, object_id_t setObjectId,
|
||||||
|
object_id_t setPacketSource);
|
||||||
/**
|
/**
|
||||||
* The destructor is empty.
|
* The destructor is empty.
|
||||||
*/
|
*/
|
||||||
virtual ~PUSDistributor();
|
virtual ~PUSDistributor();
|
||||||
ReturnValue_t registerService(AcceptsTelecommandsIF* service);
|
ReturnValue_t registerService(AcceptsTelecommandsIF* service) override;
|
||||||
MessageQueueId_t getRequestQueue();
|
MessageQueueId_t getRequestQueue() override;
|
||||||
uint16_t getIdentifier();
|
ReturnValue_t initialize() override;
|
||||||
ReturnValue_t initialize();
|
uint16_t getIdentifier() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* This attribute contains the class, that performs a formal packet check.
|
* This attribute contains the class, that performs a formal packet check.
|
||||||
*/
|
*/
|
||||||
TcPacketCheck checker;
|
TcPacketCheck checker;
|
||||||
/**
|
/**
|
||||||
* With this class, verification messages are sent to the TC Verification service.
|
* With this class, verification messages are sent to the
|
||||||
|
* TC Verification service.
|
||||||
*/
|
*/
|
||||||
VerificationReporter verifyChannel;
|
VerificationReporter verifyChannel;
|
||||||
/**
|
/**
|
||||||
@ -47,21 +52,26 @@ protected:
|
|||||||
*/
|
*/
|
||||||
TcPacketStored currentPacket;
|
TcPacketStored currentPacket;
|
||||||
/**
|
/**
|
||||||
* With this variable, the current check status is stored to generate acceptance messages later.
|
* With this variable, the current check status is stored to generate
|
||||||
|
* acceptance messages later.
|
||||||
*/
|
*/
|
||||||
ReturnValue_t tcStatus;
|
ReturnValue_t tcStatus;
|
||||||
|
|
||||||
const object_id_t packetSource;
|
const object_id_t packetSource;
|
||||||
/**
|
/**
|
||||||
* This method reads the packet service, checks if such a service is registered and forwards the packet to the destination.
|
* This method reads the packet service, checks if such a service is
|
||||||
* It also initiates the formal packet check and sending of verification messages.
|
* registered and forwards the packet to the destination.
|
||||||
* @return Iterator to map entry of found service id or iterator to \c map.end().
|
* It also initiates the formal packet check and sending of verification
|
||||||
|
* messages.
|
||||||
|
* @return Iterator to map entry of found service id
|
||||||
|
* or iterator to @c map.end().
|
||||||
*/
|
*/
|
||||||
iterator_t selectDestination();
|
TcMessageQueueMapIter selectDestination();
|
||||||
/**
|
/**
|
||||||
* The callback here handles the generation of acceptance success/failure messages.
|
* The callback here handles the generation of acceptance
|
||||||
|
* success/failure messages.
|
||||||
*/
|
*/
|
||||||
ReturnValue_t callbackAfterSending(ReturnValue_t queueStatus);
|
ReturnValue_t callbackAfterSending(ReturnValue_t queueStatus);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* PUSDISTRIBUTOR_H_ */
|
#endif /* FRAMEWORK_TCDISTRIBUTION_PUSDISTRIBUTOR_H_ */
|
||||||
|
@ -15,7 +15,6 @@ TcDistributor::~TcDistributor() {
|
|||||||
|
|
||||||
ReturnValue_t TcDistributor::performOperation(uint8_t opCode) {
|
ReturnValue_t TcDistributor::performOperation(uint8_t opCode) {
|
||||||
ReturnValue_t status = RETURN_OK;
|
ReturnValue_t status = RETURN_OK;
|
||||||
// debug << "TcDistributor: performing Operation." << std::endl;
|
|
||||||
for (status = tcQueue->receiveMessage(¤tMessage); status == RETURN_OK;
|
for (status = tcQueue->receiveMessage(¤tMessage); status == RETURN_OK;
|
||||||
status = tcQueue->receiveMessage(¤tMessage)) {
|
status = tcQueue->receiveMessage(¤tMessage)) {
|
||||||
status = handlePacket();
|
status = handlePacket();
|
||||||
@ -29,7 +28,7 @@ ReturnValue_t TcDistributor::performOperation(uint8_t opCode) {
|
|||||||
|
|
||||||
ReturnValue_t TcDistributor::handlePacket() {
|
ReturnValue_t TcDistributor::handlePacket() {
|
||||||
|
|
||||||
iterator_t queueMapIt = this->selectDestination();
|
TcMessageQueueMapIter queueMapIt = this->selectDestination();
|
||||||
ReturnValue_t returnValue = RETURN_FAILED;
|
ReturnValue_t returnValue = RETURN_FAILED;
|
||||||
if (queueMapIt != this->queueMap.end()) {
|
if (queueMapIt != this->queueMap.end()) {
|
||||||
returnValue = this->tcQueue->sendMessage(queueMapIt->second,
|
returnValue = this->tcQueue->sendMessage(queueMapIt->second,
|
||||||
@ -41,7 +40,7 @@ ReturnValue_t TcDistributor::handlePacket() {
|
|||||||
void TcDistributor::print() {
|
void TcDistributor::print() {
|
||||||
sif::debug << "Distributor content is: " << std::endl << "ID\t| message queue id"
|
sif::debug << "Distributor content is: " << std::endl << "ID\t| message queue id"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
for (iterator_t it = this->queueMap.begin(); it != this->queueMap.end();
|
for (TcMessageQueueMapIter it = this->queueMap.begin(); it != this->queueMap.end();
|
||||||
it++) {
|
it++) {
|
||||||
sif::debug << it->first << "\t| 0x" << std::hex << it->second << std::dec
|
sif::debug << it->first << "\t| 0x" << std::hex << it->second << std::dec
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#ifndef TCDISTRIBUTOR_H_
|
#ifndef FRAMEWORK_TMTCSERVICES_TCDISTRIBUTOR_H_
|
||||||
#define TCDISTRIBUTOR_H_
|
#define FRAMEWORK_TMTCSERVICES_TCDISTRIBUTOR_H_
|
||||||
|
|
||||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||||
#include <framework/objectmanager/SystemObject.h>
|
#include <framework/objectmanager/SystemObject.h>
|
||||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||||
@ -9,16 +10,12 @@
|
|||||||
#include <framework/ipc/MessageQueueIF.h>
|
#include <framework/ipc/MessageQueueIF.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \defgroup tc_distribution Telecommand Distribution
|
* @defgroup tc_distribution Telecommand Distribution
|
||||||
* All classes associated with Routing and Distribution of Telecommands belong to this group.
|
* All classes associated with Routing and Distribution of Telecommands
|
||||||
|
* belong to this group.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* This typedef simplifies writing down the \c map iterator.
|
|
||||||
*/
|
|
||||||
typedef std::map<uint32_t, MessageQueueId_t>::iterator iterator_t;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the base class to implement distributors for Space Packets.
|
* This is the base class to implement distributors for Space Packets.
|
||||||
@ -28,59 +25,15 @@ typedef std::map<uint32_t, MessageQueueId_t>::iterator iterator_t;
|
|||||||
* message queue ids to some identifier. The process of unpacking the
|
* message queue ids to some identifier. The process of unpacking the
|
||||||
* destination information from the packet is handled by the child class
|
* destination information from the packet is handled by the child class
|
||||||
* implementations.
|
* implementations.
|
||||||
* \ingroup tc_distribution
|
* @ingroup tc_distribution
|
||||||
*/
|
*/
|
||||||
class TcDistributor : public SystemObject, public ExecutableObjectIF, public HasReturnvaluesIF {
|
class TcDistributor : public SystemObject,
|
||||||
private:
|
public ExecutableObjectIF,
|
||||||
/**
|
public HasReturnvaluesIF {
|
||||||
* This constant sets the maximum number of packets distributed per call.
|
|
||||||
*/
|
|
||||||
static const uint8_t DISTRIBUTER_MAX_PACKETS = 128;
|
|
||||||
protected:
|
|
||||||
/**
|
|
||||||
* This is the receiving queue for incoming Telecommands.
|
|
||||||
* The child classes must make its queue id public.
|
|
||||||
*/
|
|
||||||
MessageQueueIF* tcQueue;
|
|
||||||
/**
|
|
||||||
* The last received incoming packet information is stored in this
|
|
||||||
* member.
|
|
||||||
* As different child classes unpack the incoming packet differently
|
|
||||||
* (i.e. as a CCSDS Space Packet or as a PUS Telecommand Packet), it
|
|
||||||
* is not tried to unpack the packet information within this class.
|
|
||||||
*/
|
|
||||||
TmTcMessage currentMessage;
|
|
||||||
/**
|
|
||||||
* The map that links certain packet information to a destination.
|
|
||||||
* The packet information may be the APID of the packet or the service
|
|
||||||
* identifier. Filling of the map is under control of the different child
|
|
||||||
* classes.
|
|
||||||
*/
|
|
||||||
std::map<uint32_t, MessageQueueId_t> queueMap;
|
|
||||||
/**
|
|
||||||
* This method shall unpack the routing information from the incoming
|
|
||||||
* packet and select the map entry which represents the packet's target.
|
|
||||||
* @return An iterator to the map element to forward to or queuMap.end().
|
|
||||||
*/
|
|
||||||
virtual iterator_t selectDestination() = 0;
|
|
||||||
/**
|
|
||||||
* The handlePacket method calls the child class's selectDestination method
|
|
||||||
* and forwards the packet to its destination, if found.
|
|
||||||
* @return The message queue return value or \c RETURN_FAILED, in case no
|
|
||||||
* destination was found.
|
|
||||||
*/
|
|
||||||
ReturnValue_t handlePacket();
|
|
||||||
/**
|
|
||||||
* This method gives the child class a chance to perform some kind of operation
|
|
||||||
* after the parent tried to forward the message.
|
|
||||||
* A typically application would be sending success/failure messages.
|
|
||||||
* The default implementation just returns \c RETURN_OK.
|
|
||||||
* @param queueStatus The status of the message queue after an attempt to send the TC.
|
|
||||||
* @return - \c RETURN_OK on success
|
|
||||||
* - \c RETURN_FAILED on failure
|
|
||||||
*/
|
|
||||||
virtual ReturnValue_t callbackAfterSending( ReturnValue_t queueStatus );
|
|
||||||
public:
|
public:
|
||||||
|
using TcMessageQueueMap = std::map<uint32_t, MessageQueueId_t>;
|
||||||
|
using TcMessageQueueMapIter = std::map<uint32_t, MessageQueueId_t>::iterator;
|
||||||
|
|
||||||
static const uint8_t INTERFACE_ID = CLASS_ID::PACKET_DISTRIBUTION;
|
static const uint8_t INTERFACE_ID = CLASS_ID::PACKET_DISTRIBUTION;
|
||||||
static const ReturnValue_t PACKET_LOST = MAKE_RETURN_CODE( 1 );
|
static const ReturnValue_t PACKET_LOST = MAKE_RETURN_CODE( 1 );
|
||||||
static const ReturnValue_t DESTINATION_NOT_FOUND = MAKE_RETURN_CODE( 2 );
|
static const ReturnValue_t DESTINATION_NOT_FOUND = MAKE_RETURN_CODE( 2 );
|
||||||
@ -110,6 +63,57 @@ public:
|
|||||||
* queueMap.
|
* queueMap.
|
||||||
*/
|
*/
|
||||||
void print();
|
void print();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* This is the receiving queue for incoming Telecommands.
|
||||||
|
* The child classes must make its queue id public.
|
||||||
|
*/
|
||||||
|
MessageQueueIF* tcQueue;
|
||||||
|
/**
|
||||||
|
* The last received incoming packet information is stored in this
|
||||||
|
* member.
|
||||||
|
* As different child classes unpack the incoming packet differently
|
||||||
|
* (i.e. as a CCSDS Space Packet or as a PUS Telecommand Packet), it
|
||||||
|
* is not tried to unpack the packet information within this class.
|
||||||
|
*/
|
||||||
|
TmTcMessage currentMessage;
|
||||||
|
/**
|
||||||
|
* The map that links certain packet information to a destination.
|
||||||
|
* The packet information may be the APID of the packet or the service
|
||||||
|
* identifier. Filling of the map is under control of the different child
|
||||||
|
* classes.
|
||||||
|
*/
|
||||||
|
TcMessageQueueMap queueMap;
|
||||||
|
/**
|
||||||
|
* This method shall unpack the routing information from the incoming
|
||||||
|
* packet and select the map entry which represents the packet's target.
|
||||||
|
* @return An iterator to the map element to forward to or queuMap.end().
|
||||||
|
*/
|
||||||
|
virtual TcMessageQueueMapIter selectDestination() = 0;
|
||||||
|
/**
|
||||||
|
* The handlePacket method calls the child class's selectDestination method
|
||||||
|
* and forwards the packet to its destination, if found.
|
||||||
|
* @return The message queue return value or \c RETURN_FAILED, in case no
|
||||||
|
* destination was found.
|
||||||
|
*/
|
||||||
|
ReturnValue_t handlePacket();
|
||||||
|
/**
|
||||||
|
* This method gives the child class a chance to perform some kind of operation
|
||||||
|
* after the parent tried to forward the message.
|
||||||
|
* A typically application would be sending success/failure messages.
|
||||||
|
* The default implementation just returns \c RETURN_OK.
|
||||||
|
* @param queueStatus The status of the message queue after an attempt to send the TC.
|
||||||
|
* @return - \c RETURN_OK on success
|
||||||
|
* - \c RETURN_FAILED on failure
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t callbackAfterSending( ReturnValue_t queueStatus );
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* This constant sets the maximum number of packets distributed per call.
|
||||||
|
*/
|
||||||
|
static const uint8_t DISTRIBUTER_MAX_PACKETS = 128;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,9 +41,14 @@ void PusServiceBase::handleRequestQueue() {
|
|||||||
ReturnValue_t result = RETURN_FAILED;
|
ReturnValue_t result = RETURN_FAILED;
|
||||||
for (uint8_t count = 0; count < PUS_SERVICE_MAX_RECEPTION; count++) {
|
for (uint8_t count = 0; count < PUS_SERVICE_MAX_RECEPTION; count++) {
|
||||||
ReturnValue_t status = this->requestQueue->receiveMessage(&message);
|
ReturnValue_t status = this->requestQueue->receiveMessage(&message);
|
||||||
// debug << "PusServiceBase::performOperation: Receiving from MQ ID: "
|
// if(status != MessageQueueIF::EMPTY) {
|
||||||
// << std::hex << this->requestQueue.getId()
|
// sif::debug << "PusServiceBase::performOperation: Receiving from "
|
||||||
// << std::dec << " returned: " << status << std::endl;
|
// << "MQ ID: " << std::hex << "0x" << std::setw(8)
|
||||||
|
// << std::setfill('0') << this->requestQueue->getId()
|
||||||
|
// << std::dec << " returned: " << status << std::setfill(' ')
|
||||||
|
// << std::endl;
|
||||||
|
// }
|
||||||
|
|
||||||
if (status == RETURN_OK) {
|
if (status == RETURN_OK) {
|
||||||
this->currentPacket.setStoreAddress(message.getStorageId());
|
this->currentPacket.setStoreAddress(message.getStorageId());
|
||||||
//info << "Service " << (uint16_t) this->serviceId <<
|
//info << "Service " << (uint16_t) this->serviceId <<
|
||||||
|
@ -62,7 +62,7 @@ public:
|
|||||||
* @param virtualChannel
|
* @param virtualChannel
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
MessageQueueId_t getReportReceptionQueue(
|
virtual MessageQueueId_t getReportReceptionQueue(
|
||||||
uint8_t virtualChannel = 0) override;
|
uint8_t virtualChannel = 0) override;
|
||||||
protected:
|
protected:
|
||||||
//! Used to send and receive TMTC messages.
|
//! Used to send and receive TMTC messages.
|
||||||
|
Loading…
Reference in New Issue
Block a user