udp bridge for embedded linux
This commit is contained in:
parent
3cd0f8f5f0
commit
113397c6c6
@ -33,7 +33,7 @@ ReturnValue_t TcUnixUdpPollingTask::performOperation(uint8_t opCode) {
|
|||||||
while(1) {
|
while(1) {
|
||||||
//! Sender Address is cached here.
|
//! Sender Address is cached here.
|
||||||
struct sockaddr_in senderAddress;
|
struct sockaddr_in senderAddress;
|
||||||
socklen_t senderSockLen = 0;
|
socklen_t senderSockLen = sizeof(senderAddress);
|
||||||
ssize_t bytesReceived = recvfrom(serverUdpSocket,
|
ssize_t bytesReceived = recvfrom(serverUdpSocket,
|
||||||
receptionBuffer.data(), frameSize, receptionFlags,
|
receptionBuffer.data(), frameSize, receptionFlags,
|
||||||
reinterpret_cast<sockaddr*>(&senderAddress), &senderSockLen);
|
reinterpret_cast<sockaddr*>(&senderAddress), &senderSockLen);
|
||||||
@ -45,8 +45,8 @@ ReturnValue_t TcUnixUdpPollingTask::performOperation(uint8_t opCode) {
|
|||||||
|
|
||||||
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) {
|
||||||
|
@ -65,13 +65,17 @@ 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;
|
||||||
|
|
||||||
clientAddress.sin_addr.s_addr = htons(INADDR_ANY);
|
MutexHelper lock(mutex, MutexIF::TimeoutType::WAITING, 10);
|
||||||
//clientAddress.sin_addr.s_addr = inet_addr("127.73.73.1");
|
|
||||||
clientAddressLen = sizeof(serverAddress);
|
|
||||||
|
|
||||||
// char ipAddress [15];
|
if(ipAddrAnySet){
|
||||||
// sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,
|
clientAddress.sin_addr.s_addr = htons(INADDR_ANY);
|
||||||
// &clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
|
//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);
|
||||||
@ -85,7 +89,7 @@ ReturnValue_t TmTcUnixUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
|
|||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TmTcUnixUdpBridge::checkAndSetClientAddress(sockaddr_in newAddress) {
|
void TmTcUnixUdpBridge::checkAndSetClientAddress(sockaddr_in& newAddress) {
|
||||||
MutexHelper lock(mutex, MutexIF::TimeoutType::WAITING, 10);
|
MutexHelper lock(mutex, MutexIF::TimeoutType::WAITING, 10);
|
||||||
|
|
||||||
// char ipAddress [15];
|
// char ipAddress [15];
|
||||||
@ -168,3 +172,7 @@ void TmTcUnixUdpBridge::handleSendError() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TmTcUnixUdpBridge::setClientAddressToAny(bool ipAddrAnySet){
|
||||||
|
this->ipAddrAnySet = ipAddrAnySet;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -20,8 +20,9 @@ public:
|
|||||||
uint16_t serverPort = 0xFFFF,uint16_t clientPort = 0xFFFF);
|
uint16_t serverPort = 0xFFFF,uint16_t clientPort = 0xFFFF);
|
||||||
virtual~ TmTcUnixUdpBridge();
|
virtual~ TmTcUnixUdpBridge();
|
||||||
|
|
||||||
void checkAndSetClientAddress(sockaddr_in clientAddress);
|
void checkAndSetClientAddress(sockaddr_in& clientAddress);
|
||||||
|
|
||||||
|
void setClientAddressToAny(bool ipAddrAnySet);
|
||||||
protected:
|
protected:
|
||||||
virtual ReturnValue_t sendTm(const uint8_t * data, size_t dataLen) override;
|
virtual ReturnValue_t sendTm(const uint8_t * data, size_t dataLen) override;
|
||||||
|
|
||||||
@ -36,6 +37,8 @@ private:
|
|||||||
struct sockaddr_in serverAddress;
|
struct sockaddr_in serverAddress;
|
||||||
socklen_t serverAddressLen = 0;
|
socklen_t serverAddressLen = 0;
|
||||||
|
|
||||||
|
bool ipAddrAnySet = false;
|
||||||
|
|
||||||
//! 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.
|
||||||
MutexIF* mutex;
|
MutexIF* mutex;
|
||||||
|
Loading…
Reference in New Issue
Block a user