Compare commits
No commits in common. "fdd23604f5c4a29c9c0b8d757245b2063c4d3c8e" and "fe021e3b8aa65e545d97075110c5804decc0f1bc" have entirely different histories.
fdd23604f5
...
fe021e3b8a
@ -1,8 +1,6 @@
|
||||
#include "EspIdfParticipant.h"
|
||||
|
||||
#if defined(IDF_VER)
|
||||
#include "esp_wifi.h"
|
||||
#endif
|
||||
|
||||
namespace RoboidControl {
|
||||
namespace EspIdf {
|
||||
@ -37,9 +35,9 @@ void ParticipantUDP::Setup(int localPort,
|
||||
local_addr.sin_addr.s_addr =
|
||||
htonl(INADDR_ANY); // Listen on all available network interfaces
|
||||
|
||||
|
||||
// Bind the socket to the address and port
|
||||
if (bind(this->sockfd, (struct sockaddr*)&local_addr, sizeof(local_addr)) <
|
||||
0) {
|
||||
if (bind(this->sockfd, (struct sockaddr*)&local_addr, sizeof(local_addr)) < 0) {
|
||||
std::cout << "Unable to bind UDP socket: errno " << errno << "\n";
|
||||
close(sockfd);
|
||||
vTaskDelete(NULL);
|
||||
@ -47,12 +45,11 @@ void ParticipantUDP::Setup(int localPort,
|
||||
}
|
||||
|
||||
// Initialize the dest_addr structure
|
||||
memset(&this->dest_addr, 0,
|
||||
sizeof(this->dest_addr)); // Clear the entire structure
|
||||
memset(&this->dest_addr, 0, sizeof(this->dest_addr)); // Clear the entire structure
|
||||
this->dest_addr.sin_family = AF_INET;
|
||||
this->dest_addr.sin_port = htons(this->remoteSite->port);
|
||||
inet_pton(AF_INET, this->remoteSite->ipAddress,
|
||||
&this->dest_addr.sin_addr.s_addr);
|
||||
inet_pton(AF_INET, this->remoteSite->ipAddress, &this->dest_addr.sin_addr.s_addr);
|
||||
|
||||
|
||||
std::cout << "Wifi sync started local " << this->port << ", remote "
|
||||
<< this->remoteSite->ipAddress << ":" << this->remoteSite->port
|
||||
@ -61,7 +58,6 @@ void ParticipantUDP::Setup(int localPort,
|
||||
}
|
||||
|
||||
void ParticipantUDP::GetBroadcastAddress() {
|
||||
#if defined(IDF_VER)
|
||||
// SOMEHOW, THIS FUNCTION RESULTS IN MEMORY CORRUPION...
|
||||
|
||||
esp_netif_ip_info_t ip_info;
|
||||
@ -80,7 +76,6 @@ void ParticipantUDP::GetBroadcastAddress() {
|
||||
snprintf(this->broadcastIpAddress, INET_ADDRSTRLEN, IPSTR,
|
||||
IP2STR(&broadcast_addr.u_addr.ip4));
|
||||
std::cout << "Broadcast address: " << this->broadcastIpAddress << "\n";
|
||||
#endif // IDF_VER
|
||||
}
|
||||
|
||||
void ParticipantUDP::Receive() {
|
||||
@ -112,8 +107,7 @@ void ParticipantUDP::Receive() {
|
||||
break;
|
||||
}
|
||||
|
||||
// std::cout << "receiving " << packetSize << " bytes, msgId " <<
|
||||
// (int)this->buffer[0] << "\n";
|
||||
// std::cout << "receiving " << packetSize << " bytes, msgId " << (int)this->buffer[0] << "\n";
|
||||
inet_ntoa_r(source_addr.sin_addr, sender_ipAddress, INET_ADDRSTRLEN);
|
||||
unsigned int sender_port = ntohs(source_addr.sin_port);
|
||||
|
||||
@ -135,8 +129,8 @@ bool ParticipantUDP::Send(Participant* remoteParticipant, int bufferSize) {
|
||||
std::cout << "Sending to " << remoteParticipant->ipAddress << ":"
|
||||
<< remoteParticipant->port << "\n";
|
||||
|
||||
int err = sendto(this->sockfd, buffer, bufferSize, 0,
|
||||
(struct sockaddr*)&dest_addr, sizeof(dest_addr));
|
||||
int err = sendto(this->sockfd, buffer, bufferSize, 0, (struct sockaddr*)&dest_addr,
|
||||
sizeof(dest_addr));
|
||||
if (errno != 0)
|
||||
std::cout << "Send error " << err << " or " << errno << "\n";
|
||||
|
||||
|
@ -2,9 +2,7 @@
|
||||
|
||||
#include "Participants/ParticipantUDP.h"
|
||||
|
||||
#if defined(IDF_VER)
|
||||
#include "lwip/sockets.h"
|
||||
#endif
|
||||
|
||||
namespace RoboidControl {
|
||||
namespace EspIdf {
|
||||
@ -17,13 +15,12 @@ class ParticipantUDP : public RoboidControl::ParticipantUDP {
|
||||
bool Publish(IMessage* msg);
|
||||
|
||||
protected:
|
||||
#if defined(IDF_VER)
|
||||
char broadcastIpAddress[INET_ADDRSTRLEN];
|
||||
char broadcastIpAddress[INET_ADDRSTRLEN]; // IPv4 address can have a max of 15 characters
|
||||
// + null terminator
|
||||
|
||||
int sockfd;
|
||||
struct sockaddr_in dest_addr;
|
||||
//struct sockaddr_in src_addr;
|
||||
#endif
|
||||
|
||||
void GetBroadcastAddress();
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user