diff --git a/CMakeLists.txt b/CMakeLists.txt index f660483..18722d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,21 @@ 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) idf_component_register( - SRC_DIRS "." "LinearAlgebra" + SRCS ${srcs} INCLUDE_DIRS "." "LinearAlgebra" + REQUIRES esp_netif esp_wifi ) else() project(RoboidControl) @@ -28,14 +41,6 @@ else() . LinearAlgebra ) - file(GLOB srcs - *.cpp - Things/*.cpp - Messages/*.cpp - Arduino/*.cpp - Posix/*.cpp - Windows/*.cpp - ) add_library(RoboidControl STATIC ${srcs}) enable_testing() diff --git a/EspIdf/EspIdfParticipant.cpp b/EspIdf/EspIdfParticipant.cpp index ef5c7f7..9f8004c 100644 --- a/EspIdf/EspIdfParticipant.cpp +++ b/EspIdf/EspIdfParticipant.cpp @@ -1,21 +1,11 @@ #include "EspIdfParticipant.h" +#include "esp_wifi.h" +#include "lwip/sockets.h" + namespace RoboidControl { namespace EspIdf { -// #include -// #include -#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, const char* remoteIpAddress, int remotePort) { @@ -31,10 +21,10 @@ void LocalParticipant::Setup(int localPort, return; } - struct sockaddr_in server_addr, client_addr; - socklen_t addr_len = sizeof(client_addr); - char recv_buffer[1024]; - // int sockfd; + struct sockaddr_in server_addr; //, client_addr; + // socklen_t addr_len = sizeof(client_addr); + // char recv_buffer[1024]; + // int sockfd; // Create a UDP socket sockfd = socket(AF_INET, SOCK_DGRAM, 0); @@ -96,7 +86,6 @@ void LocalParticipant::Receive() { int packetSize = recvfrom(sockfd, buffer, sizeof(buffer) - 1, 0, (struct sockaddr*)&client_addr, &addr_len); while (packetSize > 0) { - char sender_ipAddress[16]; inet_ntoa_r(client_addr.sin_addr, sender_ipAddress, INET_ADDRSTRLEN); unsigned int sender_port = client_addr.sin_port; @@ -116,7 +105,7 @@ void LocalParticipant::Receive() { // ReceiveData(packetSize, remoteParticipant); ReceiveData(packetSize, sender_ipAddress, sender_port); packetSize = recvfrom(sockfd, buffer, sizeof(buffer) - 1, 0, - (struct sockaddr*)&client_addr, &addr_len); + (struct sockaddr*)&client_addr, &addr_len); } #endif } @@ -127,10 +116,13 @@ bool LocalParticipant::Send(Participant* remoteParticipant, int bufferSize) { // << remoteParticipant->port << "\n"; struct sockaddr_in dest_addr; - dest_addr.sin_family = AF_INET; - dest_addr.sin_port = htons(remoteParticipant->port); - 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)); + dest_addr.sin_family = AF_INET; + dest_addr.sin_port = htons(remoteParticipant->port); + 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)); + if (err != 0) + std::cout << "Send error\n"; #endif return true; @@ -142,14 +134,17 @@ bool LocalParticipant::Publish(IMessage* msg) { if (bufferSize <= 0) return true; - struct sockaddr_in dest_addr; - dest_addr.sin_family = AF_INET; - dest_addr.sin_port = htons(this->remotePort); - 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)); -// udp.beginPacket(this->broadcastIpAddress, this->remotePort); -// udp.write((unsigned char*)buffer, bufferSize); -// udp.endPacket(); + struct sockaddr_in dest_addr; + dest_addr.sin_family = AF_INET; + dest_addr.sin_port = htons(this->remotePort); + 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)); + if (err != 0) + 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 << ":" // << this->remotePort << "\n"; diff --git a/EspIdf/EspIdfParticipant.h b/EspIdf/EspIdfParticipant.h index ec0d147..2d90d2e 100644 --- a/EspIdf/EspIdfParticipant.h +++ b/EspIdf/EspIdfParticipant.h @@ -2,10 +2,6 @@ #include "../LocalParticipant.h" -// #if defined(HAS_WIFI) -// #include -// #endif - namespace RoboidControl { namespace EspIdf { diff --git a/EspIdf/EspIdfUtils.cpp b/EspIdf/EspIdfUtils.cpp index 2954e49..951a31f 100644 --- a/EspIdf/EspIdfUtils.cpp +++ b/EspIdf/EspIdfUtils.cpp @@ -2,7 +2,7 @@ #if defined(IDF_VER) #include -#include "esp_event.h" +// #include "esp_event.h" #include "esp_netif.h" #include "esp_wifi.h" #include "string.h" @@ -26,9 +26,9 @@ static void wifi_event_handler(void* arg, esp_wifi_connect(); } else if (event_base == IP_EVENT) { if (event_id == IP_EVENT_STA_GOT_IP) { - ip_event_got_ip_t* event = (ip_event_got_ip_t*)event_data; - std::cout << "Wifi connected, IP address " << (IP2STR(&event->ip_info.ip)) - << "\n"; + //ip_event_got_ip_t* event = (ip_event_got_ip_t*)event_data; + //const char* ipaddr = IP2STR(&event->ip_info.ip); + std::cout << "Wifi connected, IP address (tbd)\n"; wifi_connected = true; xSemaphoreGive(wifi_semaphore); // Signal that connection is established } @@ -82,7 +82,7 @@ bool StartWifi(const char* wifiSsid, const char* wifiPassword) { } if (!wifi_connected) - std::cout << "\nCould not connect to home network.\n"; + std::cout << "\nCould not connect to home network.\n"; return success; } diff --git a/LinearAlgebra/Angle.h b/LinearAlgebra/Angle.h index 4e23f9c..e82b3af 100644 --- a/LinearAlgebra/Angle.h +++ b/LinearAlgebra/Angle.h @@ -209,7 +209,7 @@ class AngleOf { private: T value; - AngleOf(T rawValue); + AngleOf(T rawValue); }; using AngleSingle = AngleOf; diff --git a/LinearAlgebra/Direction.h b/LinearAlgebra/Direction.h index efd8c4b..57f6647 100644 --- a/LinearAlgebra/Direction.h +++ b/LinearAlgebra/Direction.h @@ -30,11 +30,11 @@ class DirectionOf { AngleOf vertical; /// @brief Create a new direction with zero angles - DirectionOf(); + DirectionOf(); /// @brief Create a new direction /// @param horizontal The horizontal angle /// @param vertical The vertical angle. - DirectionOf(AngleOf horizontal, AngleOf vertical); + DirectionOf(AngleOf horizontal, AngleOf vertical); /// @brief Convert the direction into a carthesian vector /// @return The carthesian vector corresponding to this direction. diff --git a/LinearAlgebra/Spherical.h b/LinearAlgebra/Spherical.h index 86705f9..5cad52c 100644 --- a/LinearAlgebra/Spherical.h +++ b/LinearAlgebra/Spherical.h @@ -24,9 +24,9 @@ class SphericalOf { /// @brief The direction of the vector DirectionOf direction; - SphericalOf(); - SphericalOf(float distance, AngleOf horizontal, AngleOf vertical); - SphericalOf(float distance, DirectionOf direction); + SphericalOf(); + SphericalOf(float distance, AngleOf horizontal, AngleOf vertical); + SphericalOf(float distance, DirectionOf direction); /// @brief Create spherical vector without using AngleOf type. All given /// angles are in degrees diff --git a/LinearAlgebra/SwingTwist.h b/LinearAlgebra/SwingTwist.h index dc512ce..1800e43 100644 --- a/LinearAlgebra/SwingTwist.h +++ b/LinearAlgebra/SwingTwist.h @@ -21,9 +21,9 @@ class SwingTwistOf { DirectionOf swing; AngleOf twist; - SwingTwistOf(); - SwingTwistOf(DirectionOf swing, AngleOf twist); - SwingTwistOf(AngleOf horizontal, AngleOf vertical, AngleOf twist); + SwingTwistOf(); + SwingTwistOf(DirectionOf swing, AngleOf twist); + SwingTwistOf(AngleOf horizontal, AngleOf vertical, AngleOf twist); static SwingTwistOf Degrees(float horizontal, float vertical = 0,