added new tcp code
This commit is contained in:
parent
98deac1ef1
commit
df0adfb33c
@ -5,6 +5,7 @@
|
|||||||
#include "TcpTmTcBridge.h"
|
#include "TcpTmTcBridge.h"
|
||||||
#include "tcpipHelpers.h"
|
#include "tcpipHelpers.h"
|
||||||
|
|
||||||
|
#include "fsfw/tasks/TaskFactory.h"
|
||||||
#include "fsfw/container/SharedRingBuffer.h"
|
#include "fsfw/container/SharedRingBuffer.h"
|
||||||
#include "fsfw/ipc/MessageQueueSenderIF.h"
|
#include "fsfw/ipc/MessageQueueSenderIF.h"
|
||||||
#include "fsfw/ipc/MutexGuard.h"
|
#include "fsfw/ipc/MutexGuard.h"
|
||||||
@ -19,6 +20,7 @@
|
|||||||
#elif defined(PLATFORM_UNIX)
|
#elif defined(PLATFORM_UNIX)
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
#ifndef FSFW_TCP_RECV_WIRETAPPING_ENABLED
|
#ifndef FSFW_TCP_RECV_WIRETAPPING_ENABLED
|
||||||
#define FSFW_TCP_RECV_WIRETAPPING_ENABLED 0
|
#define FSFW_TCP_RECV_WIRETAPPING_ENABLED 0
|
||||||
@ -148,24 +150,67 @@ ReturnValue_t TcpTmTcServer::initializeAfterTaskCreation() {
|
|||||||
|
|
||||||
void TcpTmTcServer::handleServerOperation(socket_t connSocket) {
|
void TcpTmTcServer::handleServerOperation(socket_t connSocket) {
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
do {
|
using namespace std::chrono_literals;
|
||||||
// Read all telecommands sent by the client
|
|
||||||
retval = recv(connSocket,
|
// Receive until the peer shuts down the connection, use select to do this
|
||||||
reinterpret_cast<char*>(receptionBuffer.data()),
|
fd_set rfds;
|
||||||
receptionBuffer.capacity(),
|
fd_set efds;
|
||||||
tcpFlags);
|
|
||||||
if (retval > 0) {
|
FD_ZERO(&rfds);
|
||||||
handleTcReception(retval);
|
FD_SET(connSocket, &rfds);
|
||||||
|
|
||||||
|
FD_ZERO(&efds);
|
||||||
|
FD_SET(connSocket, &efds);
|
||||||
|
|
||||||
|
timeval tv;
|
||||||
|
tv.tv_sec = 1;
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
|
||||||
|
int nfds = connSocket + 1;
|
||||||
|
|
||||||
|
// do {
|
||||||
|
// // Read all telecommands sent by the client
|
||||||
|
// retval = recv(
|
||||||
|
// connSocket,
|
||||||
|
// reinterpret_cast<char*>(receptionBuffer.data()),
|
||||||
|
// receptionBuffer.capacity(),
|
||||||
|
// tcpFlags
|
||||||
|
// );
|
||||||
|
// if (retval > 0) {
|
||||||
|
// handleTcReception(retval);
|
||||||
|
// }
|
||||||
|
// else if(retval == 0) {
|
||||||
|
// // Client has finished sending telecommands, send telemetry now
|
||||||
|
// handleTmSending(connSocket);
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// // Should not happen
|
||||||
|
// tcpip::handleError(tcpip::Protocol::TCP, tcpip::ErrorSources::RECV_CALL);
|
||||||
|
// }
|
||||||
|
// } while(retval > 0);
|
||||||
|
while (true) {
|
||||||
|
uint32_t index = 0;
|
||||||
|
int retval = select(nfds, &rfds, nullptr, &efds, &tv);
|
||||||
|
if(retval < 0) {
|
||||||
|
// client might have shut down connection?
|
||||||
|
}
|
||||||
|
else if(retval > 0) {
|
||||||
|
if(FD_ISSET(connSocket, &rfds)) {
|
||||||
|
// data available
|
||||||
|
//int result = receiveData();
|
||||||
|
//if(result == 0) {
|
||||||
|
// break;
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
if(FD_ISSET(connSocket, &efds)) {
|
||||||
|
//spdlog::error("{}: Exception detected on receive FD", tcpip::SERVER_PR);
|
||||||
}
|
}
|
||||||
else if(retval == 0) {
|
|
||||||
// Client has finished sending telecommands, send telemetry now
|
|
||||||
handleTmSending(connSocket);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Should not happen
|
// no data available
|
||||||
tcpip::handleError(tcpip::Protocol::TCP, tcpip::ErrorSources::RECV_CALL);
|
TaskFactory::delayTask(500);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} while(retval > 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t TcpTmTcServer::handleTcReception(size_t bytesRecvd) {
|
ReturnValue_t TcpTmTcServer::handleTcReception(size_t bytesRecvd) {
|
||||||
|
Loading…
Reference in New Issue
Block a user