Skip to content
Draft
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3056e8f
Add libcoap submodule
LasseRosenow May 8, 2025
919c64b
Remove libcoap and use it as system library
LasseRosenow May 12, 2025
be18494
Compiles
LasseRosenow May 12, 2025
70714c2
Add response handler => it works!
LasseRosenow May 26, 2025
9a53187
Add working server
LasseRosenow May 26, 2025
f3c182e
WIP tests are failing :(
LasseRosenow Jun 15, 2025
595c28e
Fix coap address compare port
LasseRosenow Jun 17, 2025
fdf705b
Tests work now, but it is a bit slow maybe?
LasseRosenow Jun 17, 2025
8647c38
Cleanup useless boolean thanks to condition variables
LasseRosenow Jun 17, 2025
ce7154c
Migrate address parsing to use libcoap api
LasseRosenow Jun 24, 2025
4af3ade
remote_address => remote_host and document coap channel constructors
LasseRosenow Jun 24, 2025
50e27f1
Cleanup server initialization code
LasseRosenow Jun 24, 2025
9c9fefe
Correctly set receive thread stack size
LasseRosenow Jun 24, 2025
3d26961
Fix stack size and use buf size define as well
LasseRosenow Jun 24, 2025
ee7e10b
Add comments
LasseRosenow Jun 24, 2025
7db6c86
Remove redundant remote_address field
LasseRosenow Jun 24, 2025
58f3000
Remove redundant coap_context field for each channel
LasseRosenow Jun 24, 2025
14d844c
Cleanup more
LasseRosenow Jun 24, 2025
5564c6d
Fix send_blocking mutex
LasseRosenow Jun 25, 2025
c7b82b8
Remove useless define semicolon
LasseRosenow Jun 25, 2025
be6fcff
Document channel by session logic a little bit
LasseRosenow Jun 25, 2025
dec99bf
Remove old files
LasseRosenow Jun 25, 2025
264735a
WIP: Add full coap integration test with full reactor_uc runtime.
LasseRosenow Jun 25, 2025
efcccee
Small cleanup
LasseRosenow Jun 25, 2025
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "external/nanopb"]
path = external/nanopb
url = https://github.com/nanopb/nanopb.git
[submodule "external/libcoap"]
path = external/libcoap
url = https://github.com/obgm/libcoap.git
39 changes: 39 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,40 @@ set(NANOPB_PATH external/nanopb)
if (PLATFORM STREQUAL "POSIX")
add_library(reactor-uc STATIC ${SOURCES})
target_link_libraries(reactor-uc PRIVATE pthread)

# Set up options before libcoap is included
set(COAP_DISABLE_DTLS ON CACHE BOOL "Disable DTLS" FORCE)
set(COAP_BUILD_DOCS OFF CACHE BOOL "Disable docs" FORCE)
set(COAP_BUILD_EXAMPLES OFF CACHE BOOL "Disable examples" FORCE)
set(COAP_BUILD_TESTS OFF CACHE BOOL "Disable tests" FORCE)

# Add libcoap as a subdirectory
add_subdirectory(external/libcoap)

# Include internal libcoap headers if needed
target_include_directories(reactor-uc PUBLIC
external/libcoap/include
external/libcoap/src
)

# Link with the libcoap static library
target_link_libraries(reactor-uc PRIVATE coap-3)


# TODO: Remove this!
# Add Unity as a subdirectory
add_subdirectory(external/Unity)

# Include internal Unity headers if needed
target_include_directories(reactor-uc PUBLIC
external/Unity/src
)

add_library(Unity STATIC external/Unity/src/unity.c)
target_include_directories(Unity PUBLIC ${UNITY_DIR}/src)

# Link with the Unity static library
target_link_libraries(reactor-uc PRIVATE Unity)
elseif (PLATFORM STREQUAL "FLEXPRET")
add_library(reactor-uc STATIC ${SOURCES})
add_subdirectory($ENV{FP_SDK_PATH} BINARY_DIR)
Expand Down Expand Up @@ -87,6 +121,10 @@ if(NETWORK_CHANNEL_TCP_POSIX)
target_compile_definitions(reactor-uc PRIVATE NETWORK_CHANNEL_TCP_POSIX)
endif()

if(NETWORK_CHANNEL_COAP)
target_compile_definitions(reactor-uc PUBLIC NETWORK_CHANNEL_COAP)
endif()

if(FEDERATED)
target_compile_definitions(reactor-uc PUBLIC FEDERATED)
endif()
Expand All @@ -109,3 +147,4 @@ if(BUILD_UNIT_TESTS)
set_target_properties( Unity PROPERTIES C_CLANG_TIDY "") # Disable clang-tidy for this external lib.
add_subdirectory(test/unit)
endif()

2 changes: 1 addition & 1 deletion examples/posix/hello/hello.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "reactor-uc/reactor-uc.h"
#include "../../common/timer_source.h"
#include "../../common/timer_source.h"

LF_DEFINE_REACTION_BODY(TimerSource, r) {
LF_SCOPE_SELF(TimerSource);
Expand Down
1 change: 1 addition & 0 deletions external/libcoap
Submodule libcoap added at 17c3fe
3 changes: 3 additions & 0 deletions include/reactor-uc/network_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ struct AsyncNetworkChannel {
#ifdef NETWORK_CHANNEL_TCP_POSIX
#include "platform/posix/tcp_ip_channel.h"
#endif
#ifdef NETWORK_CHANNEL_COAP
#include "platform/posix/coap_udp_ip_channel.h"
#endif

#elif defined(PLATFORM_ZEPHYR)
#ifdef NETWORK_CHANNEL_TCP_POSIX
Expand Down
57 changes: 57 additions & 0 deletions include/reactor-uc/platform/posix/coap_udp_ip_channel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef REACTOR_UC_COAP_UDP_IP_CHANNEL_H
#define REACTOR_UC_COAP_UDP_IP_CHANNEL_H
#include "reactor-uc/network_channel.h"
#include "reactor-uc/environment.h"
#include <pthread.h>
#include <coap3/coap.h>

#define COAP_UDP_IP_CHANNEL_EXPECTED_CONNECT_DURATION MSEC(10);
#define COAP_UDP_IP_CHANNEL_BUFFERSIZE 1024
#define COAP_UDP_IP_CHANNEL_RECV_THREAD_STACK_SIZE 2048

typedef struct CoapUdpIpChannel CoapUdpIpChannel;
typedef struct FederatedConnectionBundle FederatedConnectionBundle;

typedef enum {
COAP_REQUEST_TYPE_NONE,
COAP_REQUEST_TYPE_CONNECT,
COAP_REQUEST_TYPE_MESSAGE,
COAP_REQUEST_TYPE_DISCONNECT
} coap_request_type_t;

typedef struct CoapUdpIpChannel {
NetworkChannel super;

// Remote address etc.
coap_session_t *session;

// Threading and synchronization
pthread_mutex_t state_mutex;
pthread_cond_t state_cond;
pthread_mutex_t send_mutex;
pthread_cond_t send_cond;

NetworkChannelState state;

FederateMessage output;

// Handle message callbacks
coap_request_type_t last_request_type;
coap_mid_t last_request_mid;

FederatedConnectionBundle *federated_connection;
void (*receive_callback)(FederatedConnectionBundle *conn, const FederateMessage *message);
} CoapUdpIpChannel;

/**
* @brief Constructor for the CoapUdpIpChannel.
*
* Initializes a CoapUdpIpChannel instance with the specified remote host and protocol family.
*
* @param self Pointer to the CoapUdpIpChannel instance.
* @param remote_host The remote host address, hostname or domain E.g. 127.0.0.1, [::1] or hostname.local.
* @param remote_protocol_family The protocol family (e.g., AF_INET for IPv4 and AF_INET6 for IPv6).
*/
void CoapUdpIpChannel_ctor(CoapUdpIpChannel *self, const char *remote_host, int remote_protocol_family);

#endif
11 changes: 10 additions & 1 deletion include/reactor-uc/platform/riot/coap_udp_ip_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ struct CoapUdpIpChannel {
void (*receive_callback)(FederatedConnectionBundle *conn, const FederateMessage *message);
};

void CoapUdpIpChannel_ctor(CoapUdpIpChannel *self, const char *remote_address, int remote_protocol_family);
/**
* @brief Constructor for the CoapUdpIpChannel.
*
* Initializes a CoapUdpIpChannel instance with the specified remote host and protocol family.
*
* @param self Pointer to the CoapUdpIpChannel instance.
* @param remote_host The remote host address, hostname or domain E.g. 127.0.0.1, [::1] or hostname.local.
* @param remote_protocol_family The protocol family (e.g., AF_INET for IPv4 and AF_INET6 for IPv6).
*/
void CoapUdpIpChannel_ctor(CoapUdpIpChannel *self, const char *remote_host, int remote_protocol_family);

#endif
3 changes: 3 additions & 0 deletions src/network_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#ifdef NETWORK_CHANNEL_TCP_POSIX
#include "platform/posix/tcp_ip_channel.c"
#endif
#ifdef NETWORK_CHANNEL_COAP
#include "platform/posix/coap_udp_ip_channel.c"
#endif

#elif defined(PLATFORM_ZEPHYR)
#ifdef NETWORK_CHANNEL_TCP_POSIX
Expand Down
Loading
Loading