A lot of new features and tweaks #12

Merged
muellerr merged 17 commits from mueller_framework into front_branch 2020-07-08 18:49:10 +02:00
7 changed files with 93 additions and 50 deletions
Showing only changes of commit 236ad1b85b - Show all commits

View File

@ -53,6 +53,7 @@ ReturnValue_t TcUnixUdpPollingTask::performOperation(uint8_t opCode) {
if(result != HasReturnvaluesIF::RETURN_FAILED) { if(result != HasReturnvaluesIF::RETURN_FAILED) {
} }
tmtcBridge->registerCommConnect();
tmtcBridge->checkAndSetClientAddress(senderAddress); tmtcBridge->checkAndSetClientAddress(senderAddress);
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;

View File

@ -3,11 +3,12 @@
#include <framework/ipc/MutexHelper.h> #include <framework/ipc/MutexHelper.h>
#include <errno.h> #include <errno.h>
#include <arpa/inet.h>
TmTcUnixUdpBridge::TmTcUnixUdpBridge(object_id_t objectId, TmTcUnixUdpBridge::TmTcUnixUdpBridge(object_id_t objectId,
object_id_t ccsdsPacketDistributor, uint16_t serverPort, object_id_t tcDestination, object_id_t tmStoreId, object_id_t tcStoreId,
uint16_t clientPort): uint16_t serverPort, uint16_t clientPort):
TmTcBridge(objectId, ccsdsPacketDistributor) { TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) {
mutex = MutexFactory::instance()->createMutex(); mutex = MutexFactory::instance()->createMutex();
uint16_t setServerPort = DEFAULT_UDP_SERVER_PORT; uint16_t setServerPort = DEFAULT_UDP_SERVER_PORT;
@ -15,13 +16,14 @@ TmTcUnixUdpBridge::TmTcUnixUdpBridge(object_id_t objectId,
setServerPort = serverPort; setServerPort = serverPort;
} }
// uint16_t setClientPort = DEFAULT_UDP_CLIENT_PORT; uint16_t setClientPort = DEFAULT_UDP_CLIENT_PORT;
// if(clientPort != 0xFFFF) { if(clientPort != 0xFFFF) {
// setClientPort = clientPort; setClientPort = clientPort;
// } }
// Set up UDP socket: https://man7.org/linux/man-pages/man7/ip.7.html // Set up UDP socket: https://man7.org/linux/man-pages/man7/ip.7.html
serverSocket = socket(AF_INET, SOCK_DGRAM, 0); //clientSocket = socket(AF_INET, SOCK_DGRAM, 0);
serverSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(socket < 0) { if(socket < 0) {
sif::error << "TmTcUnixUdpBridge::TmTcUnixUdpBridge: Could not open" sif::error << "TmTcUnixUdpBridge::TmTcUnixUdpBridge: Could not open"
" UDP socket!" << std::endl; " UDP socket!" << std::endl;
@ -36,10 +38,14 @@ TmTcUnixUdpBridge::TmTcUnixUdpBridge(object_id_t objectId,
setsockopt(serverSocket, SOL_SOCKET, SO_REUSEADDR, &serverSocketOptions, setsockopt(serverSocket, SOL_SOCKET, SO_REUSEADDR, &serverSocketOptions,
sizeof(serverSocketOptions)); sizeof(serverSocketOptions));
serverSocketLen = sizeof(serverAddress); clientAddress.sin_family = AF_INET;
clientAddress.sin_addr.s_addr = htonl(INADDR_ANY);
clientAddress.sin_port = htons(setClientPort);
serverAddressLen = sizeof(serverAddress);
int result = bind(serverSocket, int result = bind(serverSocket,
reinterpret_cast<struct sockaddr*>(&serverAddress), reinterpret_cast<struct sockaddr*>(&serverAddress),
serverSocketLen); serverAddressLen);
if(result == -1) { if(result == -1) {
sif::error << "TmTcUnixUdpBridge::TmTcUnixUdpBridge: Could not bind " sif::error << "TmTcUnixUdpBridge::TmTcUnixUdpBridge: Could not bind "
"local port " << setServerPort << " to server socket!" "local port " << setServerPort << " to server socket!"
@ -54,20 +60,35 @@ 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;
ssize_t result = send(serverSocket, data, dataLen, flags); sif::debug << "Client Port: "<<ntohs(clientAddress.sin_port) << std::endl;
if(result < 0) { ssize_t bytesSent = sendto(serverSocket, data, dataLen, flags,
reinterpret_cast<sockaddr*>(&clientAddress), clientAddressLen);
if(bytesSent < 0) {
// todo: handle errors // todo: handle errors
sif::error << "TmTcUnixUdpBridge::sendTm: Send operation failed " sif::error << "TmTcUnixUdpBridge::sendTm: Send operation failed."
"with error " << strerror(errno) << std::endl; << std::endl;
sif::error << "Error: " << strerror(errno) << std::endl;
handleSendError();
} }
sif::debug << "TmTcUnixUdpBridge::sendTm: " << bytesSent << " bytes were"
" 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];
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;
// 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);
} }
} }
@ -130,3 +151,8 @@ void TmTcUnixUdpBridge::handleBindError() {
} }
} }
void TmTcUnixUdpBridge::handleSendError() {
}

View File

@ -15,7 +15,8 @@ public:
static constexpr uint16_t DEFAULT_UDP_SERVER_PORT = 7301; static constexpr uint16_t DEFAULT_UDP_SERVER_PORT = 7301;
static constexpr uint16_t DEFAULT_UDP_CLIENT_PORT = 7302; static constexpr uint16_t DEFAULT_UDP_CLIENT_PORT = 7302;
TmTcUnixUdpBridge(object_id_t objectId, object_id_t ccsdsPacketDistributor, TmTcUnixUdpBridge(object_id_t objectId, object_id_t tcDestination,
object_id_t tmStoreId, object_id_t tcStoreId,
uint16_t serverPort = 0xFFFF,uint16_t clientPort = 0xFFFF); uint16_t serverPort = 0xFFFF,uint16_t clientPort = 0xFFFF);
virtual~ TmTcUnixUdpBridge(); virtual~ TmTcUnixUdpBridge();
@ -26,13 +27,14 @@ protected:
private: private:
int serverSocket = 0; int serverSocket = 0;
const int serverSocketOptions = 0; const int serverSocketOptions = 0;
struct sockaddr_in clientAddress; struct sockaddr_in clientAddress;
socklen_t clientSocketLen = 0; socklen_t clientAddressLen = 0;
struct sockaddr_in serverAddress; struct sockaddr_in serverAddress;
socklen_t serverSocketLen = 0; socklen_t serverAddressLen = 0;
//! Access to the client address is mutex protected as it is set //! Access to the client address is mutex protected as it is set
//! by another task. //! by another task.
@ -40,6 +42,7 @@ private:
void handleSocketError(); void handleSocketError();
void handleBindError(); void handleBindError();
void handleSendError();
}; };
#endif /* FRAMEWORK_OSAL_LINUX_TMTCUNIXUDPBRIDGE_H_ */ #endif /* FRAMEWORK_OSAL_LINUX_TMTCUNIXUDPBRIDGE_H_ */

View File

@ -103,19 +103,17 @@ ReturnValue_t PusServiceBase::initialize() {
packetDestination); packetDestination);
PUSDistributorIF* distributor = objectManager->get<PUSDistributorIF>( PUSDistributorIF* distributor = objectManager->get<PUSDistributorIF>(
packetSource); packetSource);
if ((destService != nullptr) && (distributor != nullptr)) { if (destService == nullptr or distributor == nullptr) {
sif::error << "PusServiceBase::PusServiceBase: Service "
<< this->serviceId << ": Configuration error. Make sure "
<< "packetSource and packetDestination are defined correctly"
<< std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
}
this->requestQueue->setDefaultDestination( this->requestQueue->setDefaultDestination(
destService->getReportReceptionQueue()); destService->getReportReceptionQueue());
distributor->registerService(this); distributor->registerService(this);
return RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
}
else {
sif::error << "PusServiceBase::PusServiceBase: Service "
<< (uint32_t) this->serviceId << ": Configuration error."
<< " Make sure packetSource and packetDestination are defined "
"correctly" << std::endl;
return RETURN_FAILED;
}
} }
ReturnValue_t PusServiceBase::initializeAfterTaskCreation() { ReturnValue_t PusServiceBase::initializeAfterTaskCreation() {

View File

@ -5,9 +5,11 @@
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <framework/globalfunctions/arrayprinter.h> #include <framework/globalfunctions/arrayprinter.h>
TmTcBridge::TmTcBridge(object_id_t objectId, TmTcBridge::TmTcBridge(object_id_t objectId, object_id_t tcDestination,
object_id_t ccsdsPacketDistributor): SystemObject(objectId), object_id_t tmStoreId, object_id_t tcStoreId):
ccsdsPacketDistributor(ccsdsPacketDistributor) SystemObject(objectId),tmStoreId(tmStoreId), tcStoreId(tcStoreId),
tcDestination(tcDestination)
{ {
tmTcReceptionQueue = QueueFactory::instance()-> tmTcReceptionQueue = QueueFactory::instance()->
createMessageQueue(TMTC_RECEPTION_QUEUE_DEPTH); createMessageQueue(TMTC_RECEPTION_QUEUE_DEPTH);
@ -42,18 +44,24 @@ ReturnValue_t TmTcBridge::setMaxNumberOfPacketsStored(
} }
ReturnValue_t TmTcBridge::initialize() { ReturnValue_t TmTcBridge::initialize() {
tcStore = objectManager->get<StorageManagerIF>(objects::TC_STORE); tcStore = objectManager->get<StorageManagerIF>(tcStoreId);
if (tcStore == NULL) { if (tcStore == nullptr) {
return RETURN_FAILED; sif::error << "TmTcBridge::initialize: TC store invalid. Make sure"
"it is created and set up properly." << std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
} }
tmStore = objectManager->get<StorageManagerIF>(objects::TM_STORE); tmStore = objectManager->get<StorageManagerIF>(tmStoreId);
if (tmStore == NULL) { if (tmStore == nullptr) {
return RETURN_FAILED; sif::error << "TmTcBridge::initialize: TM store invalid. Make sure"
"it is created and set up properly." << std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
} }
AcceptsTelecommandsIF* tcDistributor = AcceptsTelecommandsIF* tcDistributor =
objectManager->get<AcceptsTelecommandsIF>(ccsdsPacketDistributor); objectManager->get<AcceptsTelecommandsIF>(tcDestination);
if (tcDistributor == NULL) { if (tcDistributor == nullptr) {
return RETURN_FAILED; sif::error << "TmTcBridge::initialize: TC Distributor invalid"
<< std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
} }
tmTcReceptionQueue->setDefaultDestination(tcDistributor->getRequestQueue()); tmTcReceptionQueue->setDefaultDestination(tcDistributor->getRequestQueue());

View File

@ -24,7 +24,8 @@ public:
static constexpr uint8_t DEFAULT_STORED_DATA_SENT_PER_CYCLE = 5; static constexpr uint8_t DEFAULT_STORED_DATA_SENT_PER_CYCLE = 5;
static constexpr uint8_t DEFAULT_DOWNLINK_PACKETS_STORED = 10; static constexpr uint8_t DEFAULT_DOWNLINK_PACKETS_STORED = 10;
TmTcBridge(object_id_t objectId, object_id_t ccsdsPacketDistributor); TmTcBridge(object_id_t objectId, object_id_t tcDestination,
object_id_t tmStoreId, object_id_t tcStoreId);
virtual ~TmTcBridge(); virtual ~TmTcBridge();
/** /**
@ -69,14 +70,20 @@ public:
virtual MessageQueueId_t getRequestQueue() override; virtual MessageQueueId_t getRequestQueue() override;
protected: protected:
//! Cached for initialize function.
object_id_t tmStoreId = objects::NO_OBJECT;
object_id_t tcStoreId = objects::NO_OBJECT;
object_id_t tcDestination = objects::NO_OBJECT;
//! Used to send and receive TMTC messages. //! Used to send and receive TMTC messages.
//! TmTcMessage is used to transport messages between tasks. //! TmTcMessage is used to transport messages between tasks.
MessageQueueIF* tmTcReceptionQueue = nullptr; MessageQueueIF* tmTcReceptionQueue = nullptr;
StorageManagerIF* tcStore = nullptr;
StorageManagerIF* tmStore = nullptr; StorageManagerIF* tmStore = nullptr;
object_id_t ccsdsPacketDistributor = 0; StorageManagerIF* tcStore = nullptr;
//! Used to specify whether communication link is up
bool communicationLinkUp = false; //! Used to specify whether communication link is up by default.
bool communicationLinkUp = true;
bool tmStored = false; bool tmStored = false;
/** /**

View File

@ -16,7 +16,7 @@ VerificationReporter::~VerificationReporter() {}
void VerificationReporter::sendSuccessReport(uint8_t set_report_id, void VerificationReporter::sendSuccessReport(uint8_t set_report_id,
TcPacketBase* current_packet, uint8_t set_step) { TcPacketBase* current_packet, uint8_t set_step) {
if (this->acknowledgeQueue == 0) { if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) {
this->initialize(); this->initialize();
} }
PusVerificationMessage message(set_report_id, PusVerificationMessage message(set_report_id,
@ -35,7 +35,7 @@ void VerificationReporter::sendSuccessReport(uint8_t set_report_id,
void VerificationReporter::sendSuccessReport(uint8_t set_report_id, void VerificationReporter::sendSuccessReport(uint8_t set_report_id,
uint8_t ackFlags, uint16_t tcPacketId, uint16_t tcSequenceControl, uint8_t ackFlags, uint16_t tcPacketId, uint16_t tcSequenceControl,
uint8_t set_step) { uint8_t set_step) {
if (this->acknowledgeQueue == 0) { if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) {
this->initialize(); this->initialize();
} }
PusVerificationMessage message(set_report_id, ackFlags, tcPacketId, PusVerificationMessage message(set_report_id, ackFlags, tcPacketId,
@ -52,7 +52,7 @@ void VerificationReporter::sendSuccessReport(uint8_t set_report_id,
void VerificationReporter::sendFailureReport(uint8_t report_id, void VerificationReporter::sendFailureReport(uint8_t report_id,
TcPacketBase* current_packet, ReturnValue_t error_code, uint8_t step, TcPacketBase* current_packet, ReturnValue_t error_code, uint8_t step,
uint32_t parameter1, uint32_t parameter2) { uint32_t parameter1, uint32_t parameter2) {
if (this->acknowledgeQueue == 0) { if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) {
this->initialize(); this->initialize();
} }
PusVerificationMessage message(report_id, PusVerificationMessage message(report_id,
@ -73,7 +73,7 @@ void VerificationReporter::sendFailureReport(uint8_t report_id,
uint8_t ackFlags, uint16_t tcPacketId, uint16_t tcSequenceControl, uint8_t ackFlags, uint16_t tcPacketId, uint16_t tcSequenceControl,
ReturnValue_t error_code, uint8_t step, uint32_t parameter1, ReturnValue_t error_code, uint8_t step, uint32_t parameter1,
uint32_t parameter2) { uint32_t parameter2) {
if (this->acknowledgeQueue == 0) { if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) {
this->initialize(); this->initialize();
} }
PusVerificationMessage message(report_id, ackFlags, tcPacketId, PusVerificationMessage message(report_id, ackFlags, tcPacketId,