diff --git a/osal/linux/FixedTimeslotTask.cpp b/osal/linux/FixedTimeslotTask.cpp index e5c68f9d..9d7d08f6 100644 --- a/osal/linux/FixedTimeslotTask.cpp +++ b/osal/linux/FixedTimeslotTask.cpp @@ -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; } diff --git a/osal/linux/TcUnixUdpPollingTask.cpp b/osal/linux/TcUnixUdpPollingTask.cpp index 122301da..8cf7b285 100644 --- a/osal/linux/TcUnixUdpPollingTask.cpp +++ b/osal/linux/TcUnixUdpPollingTask.cpp @@ -39,15 +39,14 @@ ReturnValue_t TcUnixUdpPollingTask::performOperation(uint8_t opCode) { reinterpret_cast(&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; + } + } +} diff --git a/osal/linux/TcUnixUdpPollingTask.h b/osal/linux/TcUnixUdpPollingTask.h index 86591e8d..d8de1458 100644 --- a/osal/linux/TcUnixUdpPollingTask.h +++ b/osal/linux/TcUnixUdpPollingTask.h @@ -61,7 +61,7 @@ private: timeval receptionTimeout; ReturnValue_t handleSuccessfullTcRead(size_t bytesRead); - + void handleReadError(); }; #endif /* FRAMEWORK_OSAL_LINUX_TCSOCKETPOLLINGTASK_H_ */ diff --git a/osal/linux/TmTcUnixUdpBridge.cpp b/osal/linux/TmTcUnixUdpBridge.cpp index 40e96561..92fbbdfa 100644 --- a/osal/linux/TmTcUnixUdpBridge.cpp +++ b/osal/linux/TmTcUnixUdpBridge.cpp @@ -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(&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: "<(&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; + } } diff --git a/pus/Service2DeviceAccess.cpp b/pus/Service2DeviceAccess.cpp index 391c1116..4648aa9c 100644 --- a/pus/Service2DeviceAccess.cpp +++ b/pus/Service2DeviceAccess.cpp @@ -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() {} diff --git a/tcdistribution/PUSDistributor.cpp b/tcdistribution/PUSDistributor.cpp index d6e20acf..969380d6 100644 --- a/tcdistribution/PUSDistributor.cpp +++ b/tcdistribution/PUSDistributor.cpp @@ -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(¤tPacket); -// 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; diff --git a/tmtcservices/CommandingServiceBase.cpp b/tmtcservices/CommandingServiceBase.cpp index 0c5f5eab..63a3d943 100644 --- a/tmtcservices/CommandingServiceBase.cpp +++ b/tmtcservices/CommandingServiceBase.cpp @@ -8,18 +8,28 @@ #include #include +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); diff --git a/tmtcservices/CommandingServiceBase.h b/tmtcservices/CommandingServiceBase.h index 700503c6..e9b5f047 100644 --- a/tmtcservices/CommandingServiceBase.h +++ b/tmtcservices/CommandingServiceBase.h @@ -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, diff --git a/tmtcservices/PusServiceBase.cpp b/tmtcservices/PusServiceBase.cpp index 4385609b..877eff3e 100644 --- a/tmtcservices/PusServiceBase.cpp +++ b/tmtcservices/PusServiceBase.cpp @@ -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; } } }