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 <<
" not found, not adding it to pst" << std::endl;
" not found, not adding it to pst" << std::dec << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}

View File

@ -39,15 +39,14 @@ ReturnValue_t TcUnixUdpPollingTask::performOperation(uint8_t opCode) {
reinterpret_cast<sockaddr*>(&senderAddress), &senderSockLen);
if(bytesReceived < 0) {
// handle error
sif::error << "TcSocketPollingTask::performOperation: recvfrom "
"failed with " << strerror(errno) << std::endl;
if(errno == EAGAIN or errno == EWOULDBLOCK) {
sif::info << "timeout" << std::endl;
}
sif::error << "TcSocketPollingTask::performOperation: Reception"
"error." << std::endl;
handleReadError();
continue;
}
sif::debug << "TcSocketPollingTask::performOperation: " << bytesReceived
<< " bytes received" << std::endl;
// sif::debug << "TcSocketPollingTask::performOperation: " << bytesReceived
// << " bytes received" << std::endl;
ReturnValue_t result = handleSuccessfullTcRead(bytesReceived);
if(result != HasReturnvaluesIF::RETURN_FAILED) {
@ -61,14 +60,14 @@ ReturnValue_t TcUnixUdpPollingTask::performOperation(uint8_t opCode) {
ReturnValue_t TcUnixUdpPollingTask::handleSuccessfullTcRead(size_t bytesRead) {
store_address_t storeId = 0;
store_address_t storeId;
ReturnValue_t result = tcStore->addData(&storeId,
receptionBuffer.data(), bytesRead);
// arrayprinter::print(receptionBuffer.data(), bytesRead);
if (result != HasReturnvaluesIF::RETURN_OK) {
sif::debug << "TcSerialPollingTask::transferPusToSoftwareBus: Data "
sif::error << "TcSerialPollingTask::transferPusToSoftwareBus: Data "
"storage failed" << std::endl;
sif::debug << "Packet size: " << bytesRead << std::endl;
sif::error << "Packet size: " << bytesRead << std::endl;
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;
ReturnValue_t handleSuccessfullTcRead(size_t bytesRead);
void handleReadError();
};
#endif /* FRAMEWORK_OSAL_LINUX_TCSOCKETPOLLINGTASK_H_ */

View File

@ -32,17 +32,20 @@ TmTcUnixUdpBridge::TmTcUnixUdpBridge(object_id_t objectId,
}
serverAddress.sin_family = AF_INET;
// 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_port = htons(setServerPort);
serverAddressLen = sizeof(serverAddress);
setsockopt(serverSocket, SOL_SOCKET, SO_REUSEADDR, &serverSocketOptions,
sizeof(serverSocketOptions));
clientAddress.sin_family = AF_INET;
clientAddress.sin_addr.s_addr = htonl(INADDR_ANY);
clientAddress.sin_port = htons(setClientPort);
clientAddressLen = sizeof(clientAddress);
serverAddressLen = sizeof(serverAddress);
int result = bind(serverSocket,
reinterpret_cast<struct sockaddr*>(&serverAddress),
serverAddressLen);
@ -60,33 +63,38 @@ TmTcUnixUdpBridge::~TmTcUnixUdpBridge() {
ReturnValue_t TmTcUnixUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
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,
reinterpret_cast<sockaddr*>(&clientAddress), clientAddressLen);
if(bytesSent < 0) {
// todo: handle errors
sif::error << "TmTcUnixUdpBridge::sendTm: Send operation failed."
<< std::endl;
sif::error << "Error: " << strerror(errno) << std::endl;
handleSendError();
}
sif::debug << "TmTcUnixUdpBridge::sendTm: " << bytesSent << " bytes were"
" sent." << std::endl;
// sif::debug << "TmTcUnixUdpBridge::sendTm: " << bytesSent << " bytes were"
// " sent." << std::endl;
return HasReturnvaluesIF::RETURN_OK;
}
void TmTcUnixUdpBridge::checkAndSetClientAddress(sockaddr_in newAddress) {
MutexHelper lock(mutex, 10);
char ipAddress [15];
sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,
&newAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
// char ipAddress [15];
// sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,
// &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.
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;
clientAddressLen = sizeof(clientAddress);
}
@ -104,11 +112,11 @@ void TmTcUnixUdpBridge::handleSocketError() {
case(ENOBUFS):
case(ENOMEM):
case(EPROTONOSUPPORT):
sif::error << "TmTcUnixBridge::TmTcUnixBridge: Socket creation failed"
sif::error << "TmTcUnixBridge::handleSocketError: Socket creation failed"
<< " with " << strerror(errno) << std::endl;
break;
default:
sif::error << "TmTcUnixBridge::TmTcUnixBridge: Unknown error"
sif::error << "TmTcUnixBridge::handleSocketError: Unknown error"
<< std::endl;
break;
}
@ -122,7 +130,7 @@ void TmTcUnixUdpBridge::handleBindError() {
Ephermeral ports can be shown with following command:
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 "
"rights while ephermeral ports should not be used as well."
<< std::endl;
@ -140,19 +148,21 @@ void TmTcUnixUdpBridge::handleBindError() {
case(ENOMEM):
case(ENOTDIR):
case(EROFS): {
sif::error << "TmTcUnixBridge::TmTcUnixBridge: Socket creation failed"
sif::error << "TmTcUnixBridge::handleBindError: Socket creation failed"
<< " with " << strerror(errno) << std::endl;
break;
}
default:
sif::error << "TmTcUnixBridge::TmTcUnixBridge: Unknown error"
sif::error << "TmTcUnixBridge::handleBindError: Unknown error"
<< std::endl;
break;
}
}
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,
uint16_t commandTimeoutSeconds):
CommandingServiceBase(objectId, apid, serviceId,
numberOfParallelCommands, commandTimeoutSeconds,
tcSource, tmDestination) {}
numberOfParallelCommands, commandTimeoutSeconds) {}
Service2DeviceAccess::~Service2DeviceAccess() {}

View File

@ -13,12 +13,12 @@ PUSDistributor::PUSDistributor(uint16_t setApid, object_id_t setObjectId,
PUSDistributor::~PUSDistributor() {}
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();
this->currentPacket.setStoreAddress(this->currentMessage.getStorageId());
if (currentPacket.getWholeData() != NULL) {
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();
queueMapIt = this->queueMap.find(queue_id);
} else {
@ -29,8 +29,8 @@ TcDistributor::TcMqMapIter PUSDistributor::selectDestination() {
}
if (tcStatus != RETURN_OK) {
sif::debug << "PUSDistributor::handlePacket: error with " << (int) tcStatus
<< ", 0x"<< std::hex << (int) tcStatus << std::endl;
sif::debug << "PUSDistributor::handlePacket: Error with " << tcStatus
<< ", 0x"<< std::hex << tcStatus << std::dec << std::endl;
return this->queueMap.end();
} else {
return queueMapIt;

View File

@ -8,18 +8,28 @@
#include <framework/tmtcpacket/pus/TcPacketStored.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,
uint16_t apid, uint8_t service, uint8_t numberOfParallelCommands,
uint16_t commandTimeoutSeconds, object_id_t setPacketSource,
object_id_t setPacketDestination, size_t queueDepth) :
uint16_t commandTimeoutSeconds, size_t queueDepth) :
SystemObject(setObjectId), apid(apid), service(service),
timeoutSeconds(commandTimeoutSeconds),
commandMap(numberOfParallelCommands), packetSource(setPacketSource),
packetDestination(setPacketDestination) {
commandMap(numberOfParallelCommands) {
commandQueue = 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() {
QueueFactory::instance()->deleteMessageQueue(commandQueue);

View File

@ -15,6 +15,10 @@
class TcPacketStored;
namespace Factory{
void setStaticFrameworkObjectIds();
}
/**
* @brief This class is the basis for all PUS Services, which have to
* relay Telecommands to software bus.
@ -33,6 +37,7 @@ class CommandingServiceBase: public SystemObject,
public AcceptsTelecommandsIF,
public ExecutableObjectIF,
public HasReturnvaluesIF {
friend void (Factory::setStaticFrameworkObjectIds)();
public:
static const uint8_t INTERFACE_ID = CLASS_ID::COMMAND_SERVICE_BASE;
static const ReturnValue_t EXECUTION_COMPLETE = MAKE_RETURN_CODE(1);
@ -57,10 +62,24 @@ public:
*/
CommandingServiceBase(object_id_t setObjectId, uint16_t apid,
uint8_t service, uint8_t numberOfParallelCommands,
uint16_t commandTimeoutSeconds, object_id_t setPacketSource,
object_id_t setPacketDestination, size_t queueDepth = 20);
uint16_t commandTimeoutSeconds, size_t queueDepth = 20);
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.
* Handle request queue for external commands.
@ -229,9 +248,8 @@ protected:
uint32_t failureParameter1 = 0;
uint32_t failureParameter2 = 0;
object_id_t packetSource;
object_id_t packetDestination;
static object_id_t packetSource;
static object_id_t packetDestination;
/**
* Pointer to the task which executes this component,

View File

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