Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/libcanard/canard_pio.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// canard_pio.c - PlatformIO/ESP-IDF wrapper for canard.c
//
// Problem: ESP-IDF's platform_include/assert.h (included by canard.c via
// <assert.h>) unconditionally includes <stdlib.h>, which in
// Espressif's picolibc declares `long int random(void)`.
// This conflicts with libcanard's internal `static uint64_t random(...)`.
//
// Fix: include <stdlib.h> here first, with _GNU_SOURCE and _BSD_SOURCE
// temporarily undefined so that random() is NOT declared. The stdlib.h
// header guard then prevents the double-inclusion that would re-declare
// random() when assert.h later pulls it in.

#undef _GNU_SOURCE
#undef _BSD_SOURCE
#include <stdlib.h>

#include "canard.c"
9 changes: 9 additions & 0 deletions lib/libcanard/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "libcanard",
"version": "4.0.0",
"build": {
"srcFilter": "+<canard_pio.c>",
"flags": ["-std=c11", "-Wno-error"],
"unflags": ["-std=gnu23", "-std=gnu17"]
}
}
8 changes: 8 additions & 0 deletions lib/o1heap/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "o1heap",
"version": "2.0.0",
"build": {
"flags": ["-std=c11", "-Wno-error"],
"unflags": ["-std=gnu23", "-std=gnu17"]
}
}
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "cyphal/timesync.hpp"
#include "cyphal/variable_fetcher.hpp"
#include "esp_efuse.h"
#include "esp_efuse_table.h"
#include "esp_timer.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
Expand Down Expand Up @@ -73,7 +74,7 @@ extern "C" void app_main() {

// Wire CAN → Cyphal
transport.SetSendFn([&](const cymon::CanFrame& f) { return can_driver.Transmit(f); });
can_driver.SetRxCallback([&transport](const cymon::CanFrame& frame) { transport.IngestFrame(frame); });
can_driver.SetRxCallback([](const cymon::CanFrame& frame) { transport.IngestFrame(frame); });

// Cyphal node
cymon::CyphalNode::NodeInfo node_info{};
Expand Down
59 changes: 51 additions & 8 deletions src/web/web_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,62 @@ bool WebServer::Start() {

// Register REST endpoints
static const httpd_uri_t uris[] = {
{"/api/nodes", HTTP_GET, HandleGetNodes, nullptr},
{"/api/session", HTTP_POST, HandlePostSession, nullptr},
{"/api/session/*", HTTP_DELETE, HandleDeleteSession, nullptr},
{"/api/wifi", HTTP_POST, HandlePostWifi, nullptr},
{"/api/can", HTTP_POST, HandlePostCan, nullptr},
{"/api/settings", HTTP_GET, HandleGetSettings, nullptr},
{.uri = "/api/nodes",
.method = HTTP_GET,
.handler = HandleGetNodes,
.user_ctx = nullptr,
.is_websocket = false,
.handle_ws_control_frames = false,
.supported_subprotocol = nullptr},
{.uri = "/api/session",
.method = HTTP_POST,
.handler = HandlePostSession,
.user_ctx = nullptr,
.is_websocket = false,
.handle_ws_control_frames = false,
.supported_subprotocol = nullptr},
{.uri = "/api/session/*",
.method = HTTP_DELETE,
.handler = HandleDeleteSession,
.user_ctx = nullptr,
.is_websocket = false,
.handle_ws_control_frames = false,
.supported_subprotocol = nullptr},
{.uri = "/api/wifi",
.method = HTTP_POST,
.handler = HandlePostWifi,
.user_ctx = nullptr,
.is_websocket = false,
.handle_ws_control_frames = false,
.supported_subprotocol = nullptr},
{.uri = "/api/can",
.method = HTTP_POST,
.handler = HandlePostCan,
.user_ctx = nullptr,
.is_websocket = false,
.handle_ws_control_frames = false,
.supported_subprotocol = nullptr},
{.uri = "/api/settings",
.method = HTTP_GET,
.handler = HandleGetSettings,
.user_ctx = nullptr,
.is_websocket = false,
.handle_ws_control_frames = false,
.supported_subprotocol = nullptr},
{.uri = "/ws",
.method = HTTP_GET,
.handler = HandleWebSocket,
.user_ctx = nullptr,
.is_websocket = true,
.handle_ws_control_frames = true},
{"/*", HTTP_GET, HandleStaticFile, nullptr}, // catch-all for SPIFFS
.handle_ws_control_frames = true,
.supported_subprotocol = nullptr},
{.uri = "/*",
.method = HTTP_GET,
.handler = HandleStaticFile,
.user_ctx = nullptr,
.is_websocket = false,
.handle_ws_control_frames = false,
.supported_subprotocol = nullptr}, // catch-all for SPIFFS
};

for (const auto& uri : uris) {
Expand Down
Loading