Linking works

This commit is contained in:
Pascal Serrarens 2025-04-02 17:25:11 +02:00
parent 42d3600cd8
commit 0c826d24be
8 changed files with 54 additions and 58 deletions

View File

@ -1,8 +1,21 @@
cmake_minimum_required(VERSION 3.13) # CMake version check cmake_minimum_required(VERSION 3.13) # CMake version check
file(GLOB srcs
*.cpp
Things/*.cpp
Messages/*.cpp
Arduino/*.cpp
Posix/*.cpp
Windows/*.cpp
EspIdf/*.cpp
LinearAlgebra/*.cpp
)
if(ESP_PLATFORM) if(ESP_PLATFORM)
idf_component_register( idf_component_register(
SRC_DIRS "." "LinearAlgebra" SRCS ${srcs}
INCLUDE_DIRS "." "LinearAlgebra" INCLUDE_DIRS "." "LinearAlgebra"
REQUIRES esp_netif esp_wifi
) )
else() else()
project(RoboidControl) project(RoboidControl)
@ -28,14 +41,6 @@ else()
. .
LinearAlgebra LinearAlgebra
) )
file(GLOB srcs
*.cpp
Things/*.cpp
Messages/*.cpp
Arduino/*.cpp
Posix/*.cpp
Windows/*.cpp
)
add_library(RoboidControl STATIC ${srcs}) add_library(RoboidControl STATIC ${srcs})
enable_testing() enable_testing()

View File

@ -1,21 +1,11 @@
#include "EspIdfParticipant.h" #include "EspIdfParticipant.h"
#include "esp_wifi.h"
#include "lwip/sockets.h"
namespace RoboidControl { namespace RoboidControl {
namespace EspIdf { namespace EspIdf {
// #include <stdio.h>
// #include <string.h>
#include "esp_log.h"
// #include "esp_system.h"
#include "esp_netif.h"
// #include "esp_event_loop.h"
#include "esp_wifi.h"
#include "lwip/sockets.h"
// #include "lwip/err.h"
// #include "lwip/sys.h"
// #include "lwip/ip_addr.h"
// #include "lwip/inet.h"
void LocalParticipant::Setup(int localPort, void LocalParticipant::Setup(int localPort,
const char* remoteIpAddress, const char* remoteIpAddress,
int remotePort) { int remotePort) {
@ -31,9 +21,9 @@ void LocalParticipant::Setup(int localPort,
return; return;
} }
struct sockaddr_in server_addr, client_addr; struct sockaddr_in server_addr; //, client_addr;
socklen_t addr_len = sizeof(client_addr); // socklen_t addr_len = sizeof(client_addr);
char recv_buffer[1024]; // char recv_buffer[1024];
// int sockfd; // int sockfd;
// Create a UDP socket // Create a UDP socket
@ -96,7 +86,6 @@ void LocalParticipant::Receive() {
int packetSize = recvfrom(sockfd, buffer, sizeof(buffer) - 1, 0, int packetSize = recvfrom(sockfd, buffer, sizeof(buffer) - 1, 0,
(struct sockaddr*)&client_addr, &addr_len); (struct sockaddr*)&client_addr, &addr_len);
while (packetSize > 0) { while (packetSize > 0) {
char sender_ipAddress[16]; char sender_ipAddress[16];
inet_ntoa_r(client_addr.sin_addr, sender_ipAddress, INET_ADDRSTRLEN); inet_ntoa_r(client_addr.sin_addr, sender_ipAddress, INET_ADDRSTRLEN);
unsigned int sender_port = client_addr.sin_port; unsigned int sender_port = client_addr.sin_port;
@ -130,7 +119,10 @@ bool LocalParticipant::Send(Participant* remoteParticipant, int bufferSize) {
dest_addr.sin_family = AF_INET; dest_addr.sin_family = AF_INET;
dest_addr.sin_port = htons(remoteParticipant->port); dest_addr.sin_port = htons(remoteParticipant->port);
inet_pton(AF_INET, remoteParticipant->ipAddress, &dest_addr.sin_addr.s_addr); inet_pton(AF_INET, remoteParticipant->ipAddress, &dest_addr.sin_addr.s_addr);
int err = sendto(sockfd, buffer, bufferSize, 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr)); int err = sendto(sockfd, buffer, bufferSize, 0, (struct sockaddr*)&dest_addr,
sizeof(dest_addr));
if (err != 0)
std::cout << "Send error\n";
#endif #endif
return true; return true;
@ -146,10 +138,13 @@ bool LocalParticipant::Publish(IMessage* msg) {
dest_addr.sin_family = AF_INET; dest_addr.sin_family = AF_INET;
dest_addr.sin_port = htons(this->remotePort); dest_addr.sin_port = htons(this->remotePort);
inet_pton(AF_INET, this->broadcastIpAddress, &dest_addr.sin_addr.s_addr); inet_pton(AF_INET, this->broadcastIpAddress, &dest_addr.sin_addr.s_addr);
int err = sendto(sockfd, buffer, bufferSize, 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr)); int err = sendto(sockfd, buffer, bufferSize, 0, (struct sockaddr*)&dest_addr,
// udp.beginPacket(this->broadcastIpAddress, this->remotePort); sizeof(dest_addr));
// udp.write((unsigned char*)buffer, bufferSize); if (err != 0)
// udp.endPacket(); std::cout << "Publish error\n";
// udp.beginPacket(this->broadcastIpAddress, this->remotePort);
// udp.write((unsigned char*)buffer, bufferSize);
// udp.endPacket();
// std::cout << "Publish to " << this->broadcastIpAddress << ":" // std::cout << "Publish to " << this->broadcastIpAddress << ":"
// << this->remotePort << "\n"; // << this->remotePort << "\n";

View File

@ -2,10 +2,6 @@
#include "../LocalParticipant.h" #include "../LocalParticipant.h"
// #if defined(HAS_WIFI)
// #include <WiFiUdp.h>
// #endif
namespace RoboidControl { namespace RoboidControl {
namespace EspIdf { namespace EspIdf {

View File

@ -2,7 +2,7 @@
#if defined(IDF_VER) #if defined(IDF_VER)
#include <iostream> #include <iostream>
#include "esp_event.h" // #include "esp_event.h"
#include "esp_netif.h" #include "esp_netif.h"
#include "esp_wifi.h" #include "esp_wifi.h"
#include "string.h" #include "string.h"
@ -26,9 +26,9 @@ static void wifi_event_handler(void* arg,
esp_wifi_connect(); esp_wifi_connect();
} else if (event_base == IP_EVENT) { } else if (event_base == IP_EVENT) {
if (event_id == IP_EVENT_STA_GOT_IP) { if (event_id == IP_EVENT_STA_GOT_IP) {
ip_event_got_ip_t* event = (ip_event_got_ip_t*)event_data; //ip_event_got_ip_t* event = (ip_event_got_ip_t*)event_data;
std::cout << "Wifi connected, IP address " << (IP2STR(&event->ip_info.ip)) //const char* ipaddr = IP2STR(&event->ip_info.ip);
<< "\n"; std::cout << "Wifi connected, IP address (tbd)\n";
wifi_connected = true; wifi_connected = true;
xSemaphoreGive(wifi_semaphore); // Signal that connection is established xSemaphoreGive(wifi_semaphore); // Signal that connection is established
} }

View File

@ -209,7 +209,7 @@ class AngleOf {
private: private:
T value; T value;
AngleOf<T>(T rawValue); AngleOf(T rawValue);
}; };
using AngleSingle = AngleOf<float>; using AngleSingle = AngleOf<float>;

View File

@ -30,11 +30,11 @@ class DirectionOf {
AngleOf<T> vertical; AngleOf<T> vertical;
/// @brief Create a new direction with zero angles /// @brief Create a new direction with zero angles
DirectionOf<T>(); DirectionOf();
/// @brief Create a new direction /// @brief Create a new direction
/// @param horizontal The horizontal angle /// @param horizontal The horizontal angle
/// @param vertical The vertical angle. /// @param vertical The vertical angle.
DirectionOf<T>(AngleOf<T> horizontal, AngleOf<T> vertical); DirectionOf(AngleOf<T> horizontal, AngleOf<T> vertical);
/// @brief Convert the direction into a carthesian vector /// @brief Convert the direction into a carthesian vector
/// @return The carthesian vector corresponding to this direction. /// @return The carthesian vector corresponding to this direction.

View File

@ -24,9 +24,9 @@ class SphericalOf {
/// @brief The direction of the vector /// @brief The direction of the vector
DirectionOf<T> direction; DirectionOf<T> direction;
SphericalOf<T>(); SphericalOf();
SphericalOf<T>(float distance, AngleOf<T> horizontal, AngleOf<T> vertical); SphericalOf(float distance, AngleOf<T> horizontal, AngleOf<T> vertical);
SphericalOf<T>(float distance, DirectionOf<T> direction); SphericalOf(float distance, DirectionOf<T> direction);
/// @brief Create spherical vector without using AngleOf type. All given /// @brief Create spherical vector without using AngleOf type. All given
/// angles are in degrees /// angles are in degrees

View File

@ -21,9 +21,9 @@ class SwingTwistOf {
DirectionOf<T> swing; DirectionOf<T> swing;
AngleOf<T> twist; AngleOf<T> twist;
SwingTwistOf<T>(); SwingTwistOf();
SwingTwistOf<T>(DirectionOf<T> swing, AngleOf<T> twist); SwingTwistOf(DirectionOf<T> swing, AngleOf<T> twist);
SwingTwistOf<T>(AngleOf<T> horizontal, AngleOf<T> vertical, AngleOf<T> twist); SwingTwistOf(AngleOf<T> horizontal, AngleOf<T> vertical, AngleOf<T> twist);
static SwingTwistOf<T> Degrees(float horizontal, static SwingTwistOf<T> Degrees(float horizontal,
float vertical = 0, float vertical = 0,