CSB static framework id setting

This commit is contained in:
Robin Müller 2020-07-08 18:18:54 +02:00
parent 236ad1b85b
commit 8046d005a4
9 changed files with 99 additions and 50 deletions

View File

@ -45,7 +45,7 @@ ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId,
} }
sif::error << "Component " << std::hex << componentId << sif::error << "Component " << std::hex << componentId <<
" not found, not adding it to pst" << std::endl; " not found, not adding it to pst" << std::dec << std::endl;
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }

View File

@ -39,15 +39,14 @@ ReturnValue_t TcUnixUdpPollingTask::performOperation(uint8_t opCode) {
reinterpret_cast<sockaddr*>(&senderAddress), &senderSockLen); reinterpret_cast<sockaddr*>(&senderAddress), &senderSockLen);
if(bytesReceived < 0) { if(bytesReceived < 0) {
// handle error // handle error
sif::error << "TcSocketPollingTask::performOperation: recvfrom " sif::error << "TcSocketPollingTask::performOperation: Reception"
"failed with " << strerror(errno) << std::endl; "error." << std::endl;
if(errno == EAGAIN or errno == EWOULDBLOCK) { handleReadError();
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(bytesReceived); ReturnValue_t result = handleSuccessfullTcRead(bytesReceived);
if(result != HasReturnvaluesIF::RETURN_FAILED) { if(result != HasReturnvaluesIF::RETURN_FAILED) {
@ -61,14 +60,14 @@ ReturnValue_t TcUnixUdpPollingTask::performOperation(uint8_t opCode) {
ReturnValue_t TcUnixUdpPollingTask::handleSuccessfullTcRead(size_t bytesRead) { ReturnValue_t TcUnixUdpPollingTask::handleSuccessfullTcRead(size_t bytesRead) {
store_address_t storeId = 0; store_address_t storeId;
ReturnValue_t result = tcStore->addData(&storeId, ReturnValue_t result = tcStore->addData(&storeId,
receptionBuffer.data(), bytesRead); receptionBuffer.data(), bytesRead);
// arrayprinter::print(receptionBuffer.data(), bytesRead); // arrayprinter::print(receptionBuffer.data(), bytesRead);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
sif::debug << "TcSerialPollingTask::transferPusToSoftwareBus: Data " sif::error << "TcSerialPollingTask::transferPusToSoftwareBus: Data "
"storage failed" << std::endl; "storage failed" << std::endl;
sif::debug << "Packet size: " << bytesRead << std::endl; sif::error << "Packet size: " << bytesRead << std::endl;
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
@ -121,4 +120,18 @@ void TcUnixUdpPollingTask::setTimeout(double timeoutSeconds) {
} }
} }
void TcUnixUdpPollingTask::handleReadError() {
switch(errno) {
case(EAGAIN): {
// todo: When working in timeout mode, this will occur more often
// and is not an error.
sif::error << "TcUnixUdpPollingTask::handleReadError: Timeout."
<< std::endl;
break;
}
default: {
sif::error << "TcUnixUdpPollingTask::handleReadError: "
<< strerror(errno) << std::endl;
}
}
}

View File

@ -61,7 +61,7 @@ private:
timeval receptionTimeout; timeval receptionTimeout;
ReturnValue_t handleSuccessfullTcRead(size_t bytesRead); ReturnValue_t handleSuccessfullTcRead(size_t bytesRead);
void handleReadError();
}; };
#endif /* FRAMEWORK_OSAL_LINUX_TCSOCKETPOLLINGTASK_H_ */ #endif /* FRAMEWORK_OSAL_LINUX_TCSOCKETPOLLINGTASK_H_ */

View File

@ -32,17 +32,20 @@ TmTcUnixUdpBridge::TmTcUnixUdpBridge(object_id_t objectId,
} }
serverAddress.sin_family = AF_INET; serverAddress.sin_family = AF_INET;
// Accept packets from any interface. // Accept packets from any interface.
//serverAddress.sin_addr.s_addr = inet_addr("127.73.73.0");
serverAddress.sin_addr.s_addr = htonl(INADDR_ANY); serverAddress.sin_addr.s_addr = htonl(INADDR_ANY);
serverAddress.sin_port = htons(setServerPort); serverAddress.sin_port = htons(setServerPort);
serverAddressLen = sizeof(serverAddress);
setsockopt(serverSocket, SOL_SOCKET, SO_REUSEADDR, &serverSocketOptions, setsockopt(serverSocket, SOL_SOCKET, SO_REUSEADDR, &serverSocketOptions,
sizeof(serverSocketOptions)); sizeof(serverSocketOptions));
clientAddress.sin_family = AF_INET; clientAddress.sin_family = AF_INET;
clientAddress.sin_addr.s_addr = htonl(INADDR_ANY); clientAddress.sin_addr.s_addr = htonl(INADDR_ANY);
clientAddress.sin_port = htons(setClientPort); clientAddress.sin_port = htons(setClientPort);
clientAddressLen = sizeof(clientAddress);
serverAddressLen = sizeof(serverAddress);
int result = bind(serverSocket, int result = bind(serverSocket,
reinterpret_cast<struct sockaddr*>(&serverAddress), reinterpret_cast<struct sockaddr*>(&serverAddress),
serverAddressLen); serverAddressLen);
@ -60,33 +63,38 @@ TmTcUnixUdpBridge::~TmTcUnixUdpBridge() {
ReturnValue_t TmTcUnixUdpBridge::sendTm(const uint8_t *data, size_t dataLen) { ReturnValue_t TmTcUnixUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
int flags = 0; int flags = 0;
sif::debug << "Client Port: "<<ntohs(clientAddress.sin_port) << std::endl;
clientAddress.sin_addr.s_addr = htons(INADDR_ANY);
//clientAddress.sin_addr.s_addr = inet_addr("127.73.73.1");
clientAddressLen = sizeof(serverAddress);
// char ipAddress [15];
// sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,
// &clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
ssize_t bytesSent = sendto(serverSocket, data, dataLen, flags, ssize_t bytesSent = sendto(serverSocket, data, dataLen, flags,
reinterpret_cast<sockaddr*>(&clientAddress), clientAddressLen); reinterpret_cast<sockaddr*>(&clientAddress), clientAddressLen);
if(bytesSent < 0) { if(bytesSent < 0) {
// todo: handle errors
sif::error << "TmTcUnixUdpBridge::sendTm: Send operation failed." sif::error << "TmTcUnixUdpBridge::sendTm: Send operation failed."
<< std::endl; << std::endl;
sif::error << "Error: " << strerror(errno) << std::endl;
handleSendError(); handleSendError();
} }
sif::debug << "TmTcUnixUdpBridge::sendTm: " << bytesSent << " bytes were" // sif::debug << "TmTcUnixUdpBridge::sendTm: " << bytesSent << " bytes were"
" sent." << std::endl; // " sent." << std::endl;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
void TmTcUnixUdpBridge::checkAndSetClientAddress(sockaddr_in newAddress) { void TmTcUnixUdpBridge::checkAndSetClientAddress(sockaddr_in newAddress) {
MutexHelper lock(mutex, 10); MutexHelper lock(mutex, 10);
char ipAddress [15]; // char ipAddress [15];
sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET, // sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,
&newAddress.sin_addr.s_addr, ipAddress, 15) << std::endl; // &newAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
// sif::debug << "IP Address Old: " << inet_ntop(AF_INET,
// &clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
sif::debug << "IP Address Old: " << inet_ntop(AF_INET,
&clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
// Set new IP address if it has changed. // Set new IP address if it has changed.
if(clientAddress.sin_addr.s_addr != newAddress.sin_addr.s_addr) { if(clientAddress.sin_addr.s_addr != newAddress.sin_addr.s_addr) {
sif::info << "setting new address" << std::endl;
clientAddress.sin_addr.s_addr = newAddress.sin_addr.s_addr; clientAddress.sin_addr.s_addr = newAddress.sin_addr.s_addr;
clientAddressLen = sizeof(clientAddress); clientAddressLen = sizeof(clientAddress);
} }
@ -104,11 +112,11 @@ void TmTcUnixUdpBridge::handleSocketError() {
case(ENOBUFS): case(ENOBUFS):
case(ENOMEM): case(ENOMEM):
case(EPROTONOSUPPORT): case(EPROTONOSUPPORT):
sif::error << "TmTcUnixBridge::TmTcUnixBridge: Socket creation failed" sif::error << "TmTcUnixBridge::handleSocketError: 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::handleSocketError: Unknown error"
<< std::endl; << std::endl;
break; break;
} }
@ -122,7 +130,7 @@ void TmTcUnixUdpBridge::handleBindError() {
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
*/ */
sif::error << "TmTcUnixBridge::TmTcUnixBridge: Port access issue." sif::error << "TmTcUnixBridge::handleBindError: Port access issue."
"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;
@ -140,19 +148,21 @@ void TmTcUnixUdpBridge::handleBindError() {
case(ENOMEM): case(ENOMEM):
case(ENOTDIR): case(ENOTDIR):
case(EROFS): { case(EROFS): {
sif::error << "TmTcUnixBridge::TmTcUnixBridge: Socket creation failed" sif::error << "TmTcUnixBridge::handleBindError: 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::handleBindError: Unknown error"
<< std::endl; << std::endl;
break; break;
} }
} }
void TmTcUnixUdpBridge::handleSendError() { void TmTcUnixUdpBridge::handleSendError() {
switch(errno) {
default:
sif::error << "Error: " << strerror(errno) << std::endl;
}
} }

View File

@ -15,8 +15,7 @@ Service2DeviceAccess::Service2DeviceAccess(object_id_t objectId,
object_id_t tmDestination, uint8_t numberOfParallelCommands, object_id_t tmDestination, uint8_t numberOfParallelCommands,
uint16_t commandTimeoutSeconds): uint16_t commandTimeoutSeconds):
CommandingServiceBase(objectId, apid, serviceId, CommandingServiceBase(objectId, apid, serviceId,
numberOfParallelCommands, commandTimeoutSeconds, numberOfParallelCommands, commandTimeoutSeconds) {}
tcSource, tmDestination) {}
Service2DeviceAccess::~Service2DeviceAccess() {} Service2DeviceAccess::~Service2DeviceAccess() {}

View File

@ -13,12 +13,12 @@ PUSDistributor::PUSDistributor(uint16_t setApid, object_id_t setObjectId,
PUSDistributor::~PUSDistributor() {} PUSDistributor::~PUSDistributor() {}
TcDistributor::TcMqMapIter PUSDistributor::selectDestination() { TcDistributor::TcMqMapIter PUSDistributor::selectDestination() {
// debug << "PUSDistributor::handlePacket received: " << this->current_packet_id.store_index << ", " << this->current_packet_id.packet_index << std::endl;
TcMqMapIter queueMapIt = this->queueMap.end(); TcMqMapIter 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(&currentPacket); tcStatus = checker.checkPacket(&currentPacket);
// info << "PUSDistributor::handlePacket: packetCheck returned with " << (int)tc_status << std::endl; // sif::debug << "PUSDistributor::handlePacket: packetCheck returned with "
// << (int)tcStatus << std::endl;
uint32_t queue_id = currentPacket.getService(); uint32_t queue_id = currentPacket.getService();
queueMapIt = this->queueMap.find(queue_id); queueMapIt = this->queueMap.find(queue_id);
} else { } else {
@ -29,8 +29,8 @@ TcDistributor::TcMqMapIter PUSDistributor::selectDestination() {
} }
if (tcStatus != RETURN_OK) { if (tcStatus != RETURN_OK) {
sif::debug << "PUSDistributor::handlePacket: error with " << (int) tcStatus sif::debug << "PUSDistributor::handlePacket: Error with " << tcStatus
<< ", 0x"<< std::hex << (int) tcStatus << std::endl; << ", 0x"<< std::hex << tcStatus << std::dec << std::endl;
return this->queueMap.end(); return this->queueMap.end();
} else { } else {
return queueMapIt; return queueMapIt;

View File

@ -8,18 +8,28 @@
#include <framework/tmtcpacket/pus/TcPacketStored.h> #include <framework/tmtcpacket/pus/TcPacketStored.h>
#include <framework/tmtcpacket/pus/TmPacketStored.h> #include <framework/tmtcpacket/pus/TmPacketStored.h>
object_id_t CommandingServiceBase::packetSource = objects::NO_OBJECT;
object_id_t CommandingServiceBase::packetDestination = objects::NO_OBJECT;
CommandingServiceBase::CommandingServiceBase(object_id_t setObjectId, CommandingServiceBase::CommandingServiceBase(object_id_t setObjectId,
uint16_t apid, uint8_t service, uint8_t numberOfParallelCommands, uint16_t apid, uint8_t service, uint8_t numberOfParallelCommands,
uint16_t commandTimeoutSeconds, object_id_t setPacketSource, uint16_t commandTimeoutSeconds, size_t queueDepth) :
object_id_t setPacketDestination, size_t queueDepth) :
SystemObject(setObjectId), apid(apid), service(service), SystemObject(setObjectId), apid(apid), service(service),
timeoutSeconds(commandTimeoutSeconds), timeoutSeconds(commandTimeoutSeconds),
commandMap(numberOfParallelCommands), packetSource(setPacketSource), commandMap(numberOfParallelCommands) {
packetDestination(setPacketDestination) {
commandQueue = QueueFactory::instance()->createMessageQueue(queueDepth); commandQueue = QueueFactory::instance()->createMessageQueue(queueDepth);
requestQueue = QueueFactory::instance()->createMessageQueue(queueDepth); requestQueue = QueueFactory::instance()->createMessageQueue(queueDepth);
} }
void CommandingServiceBase::setPacketSource(object_id_t packetSource) {
this->packetSource = packetSource;
}
void CommandingServiceBase::setPacketDestination(
object_id_t packetDestination) {
this->packetDestination = packetDestination;
}
CommandingServiceBase::~CommandingServiceBase() { CommandingServiceBase::~CommandingServiceBase() {
QueueFactory::instance()->deleteMessageQueue(commandQueue); QueueFactory::instance()->deleteMessageQueue(commandQueue);

View File

@ -15,6 +15,10 @@
class TcPacketStored; class TcPacketStored;
namespace Factory{
void setStaticFrameworkObjectIds();
}
/** /**
* @brief This class is the basis for all PUS Services, which have to * @brief This class is the basis for all PUS Services, which have to
* relay Telecommands to software bus. * relay Telecommands to software bus.
@ -33,6 +37,7 @@ class CommandingServiceBase: public SystemObject,
public AcceptsTelecommandsIF, public AcceptsTelecommandsIF,
public ExecutableObjectIF, public ExecutableObjectIF,
public HasReturnvaluesIF { public HasReturnvaluesIF {
friend void (Factory::setStaticFrameworkObjectIds)();
public: public:
static const uint8_t INTERFACE_ID = CLASS_ID::COMMAND_SERVICE_BASE; static const uint8_t INTERFACE_ID = CLASS_ID::COMMAND_SERVICE_BASE;
static const ReturnValue_t EXECUTION_COMPLETE = MAKE_RETURN_CODE(1); static const ReturnValue_t EXECUTION_COMPLETE = MAKE_RETURN_CODE(1);
@ -57,10 +62,24 @@ public:
*/ */
CommandingServiceBase(object_id_t setObjectId, uint16_t apid, CommandingServiceBase(object_id_t setObjectId, uint16_t apid,
uint8_t service, uint8_t numberOfParallelCommands, uint8_t service, uint8_t numberOfParallelCommands,
uint16_t commandTimeoutSeconds, object_id_t setPacketSource, uint16_t commandTimeoutSeconds, size_t queueDepth = 20);
object_id_t setPacketDestination, size_t queueDepth = 20);
virtual ~CommandingServiceBase(); virtual ~CommandingServiceBase();
/**
* This setter can be used to set the packet source individually instead
* of using the default static framework ID set in the factory.
* This should be called at object initialization and not during run-time!
* @param packetSource
*/
void setPacketSource(object_id_t packetSource);
/**
* This setter can be used to set the packet destination individually
* instead of using the default static framework ID set in the factory.
* This should be called at object initialization and not during run-time!
* @param packetDestination
*/
void setPacketDestination(object_id_t packetDestination);
/*** /***
* This is the periodically called function. * This is the periodically called function.
* Handle request queue for external commands. * Handle request queue for external commands.
@ -229,9 +248,8 @@ protected:
uint32_t failureParameter1 = 0; uint32_t failureParameter1 = 0;
uint32_t failureParameter2 = 0; uint32_t failureParameter2 = 0;
object_id_t packetSource; static object_id_t packetSource;
static object_id_t packetDestination;
object_id_t packetDestination;
/** /**
* Pointer to the task which executes this component, * Pointer to the task which executes this component,

View File

@ -79,9 +79,8 @@ void PusServiceBase::handleRequestQueue() {
} }
else { else {
sif::error << "PusServiceBase::performOperation: Service " sif::error << "PusServiceBase::performOperation: Service "
<< (uint16_t) this->serviceId << this->serviceId << ": Error receiving packet. Code: "
<< ": Error receiving packet. Code: " << std::hex << status << std::hex << status << std::dec << std::endl;
<< std::dec << std::endl;
} }
} }
} }