From 5c9644591c223fe2cd6f07a19b17c632d4cd9e15 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 29 Nov 2024 18:06:54 +0100 Subject: [PATCH 01/17] Add RIOT federated CoAP example and fix CoAP channel --- .../riot/coap_federated/receiver/Makefile | 29 +++++ examples/riot/coap_federated/receiver/main.c | 111 ++++++++++++++++ examples/riot/coap_federated/sender/Makefile | 29 +++++ examples/riot/coap_federated/sender/main.c | 120 ++++++++++++++++++ 4 files changed, 289 insertions(+) create mode 100755 examples/riot/coap_federated/receiver/Makefile create mode 100755 examples/riot/coap_federated/receiver/main.c create mode 100755 examples/riot/coap_federated/sender/Makefile create mode 100755 examples/riot/coap_federated/sender/main.c diff --git a/examples/riot/coap_federated/receiver/Makefile b/examples/riot/coap_federated/receiver/Makefile new file mode 100755 index 00000000..d9ac8ac7 --- /dev/null +++ b/examples/riot/coap_federated/receiver/Makefile @@ -0,0 +1,29 @@ +# name of your application +APPLICATION = lf-coap-federated-receiver + +# If no BOARD is found in the environment, use this default: +BOARD ?= native + +# Comment this out to disable code in RIOT that does safety checking +# which is not needed in a production environment but helps in the +# development process: +DEVELHELP ?= 1 + +# Change this to 0 show compiler invocation lines by default: +QUIET ?= 1 + +# Enable reactor-uc features +# CFLAGS += -DNETWORK_CHANNEL_TCP_POSIX +CFLAGS += -DNETWORK_CHANNEL_COAP_RIOT +CFLAGS += -DEVENT_QUEUE_SIZE=32 +CFLAGS += -DREACTION_QUEUE_SIZE=32 + +CFLAGS += -DTHREAD_STACKSIZE_DEFAULT=10000 +CFLAGS += -DTHREAD_STACKSIZE_MAIN=10000 +CFLAGS += -DISR_STACKSIZE=10000 + +# Configure CoAP retransmission timeout +CFLAGS+= -DCONFIG_GCOAP_NO_RETRANS_BACKOFF=1 +CFLAGS+= -DCONFIG_COAP_ACK_TIMEOUT_MS=400 + +include $(CURDIR)/../../../../make/riot/riot.mk diff --git a/examples/riot/coap_federated/receiver/main.c b/examples/riot/coap_federated/receiver/main.c new file mode 100755 index 00000000..a4d40b2e --- /dev/null +++ b/examples/riot/coap_federated/receiver/main.c @@ -0,0 +1,111 @@ +#include "reactor-uc/reactor-uc.h" +#include "reactor-uc/platform/riot/coap_udp_ip_channel.h" + +#define REMOTE_ADDRESS "fe80::4c48:d8ff:fece:9a93" +#define REMOTE_PROTOCOL_FAMILY AF_INET6 + +typedef struct { + int size; + char msg[512]; +} lf_msg_t; + +lf_ret_t deserialize_msg_t(void *user_struct, const unsigned char *msg_buf, size_t msg_size) { + (void)msg_size; + + lf_msg_t *msg = user_struct; + memcpy(&msg->size, msg_buf, sizeof(msg->size)); + memcpy(msg->msg, msg_buf + sizeof(msg->size), msg->size); + + return LF_OK; +} + +DEFINE_REACTION_STRUCT(Receiver, r, 0); +DEFINE_REACTION_CTOR(Receiver, r, 0); +DEFINE_INPUT_STRUCT(Receiver, in, 1, 0, lf_msg_t, 0); +DEFINE_INPUT_CTOR(Receiver, in, 1, 0, lf_msg_t, 0); + +typedef struct { + Reactor super; + REACTION_INSTANCE(Receiver, r); + PORT_INSTANCE(Receiver, in, 1); + int cnt; + REACTOR_BOOKKEEPING_INSTANCES(1, 1, 0); +} Receiver; + +DEFINE_REACTION_BODY(Receiver, r) { + SCOPE_SELF(Receiver); + SCOPE_ENV(); + SCOPE_PORT(Receiver, in); + printf("Input triggered @ %" PRId64 " with %s size %d\n", env->get_elapsed_logical_time(env), in->value.msg, + in->value.size); +} + +REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Receiver, InputExternalCtorArgs *in_external) { + REACTOR_CTOR_PREAMBLE(); + REACTOR_CTOR(Receiver); + INITIALIZE_REACTION(Receiver, r); + INITIALIZE_INPUT(Receiver, in, 1, in_external); + + // Register reaction as an effect of in + PORT_REGISTER_EFFECT(self->in, self->r, 1); +} + +DEFINE_FEDERATED_INPUT_CONNECTION(Receiver, in, lf_msg_t, 5, MSEC(100), false); + +typedef struct { + FederatedConnectionBundle super; + CoapUdpIpChannel channel; + FEDERATED_INPUT_CONNECTION_INSTANCE(Receiver, in); + FEDERATED_CONNECTION_BUNDLE_BOOKKEEPING_INSTANCES(1, 0) +} FEDERATED_CONNECTION_BUNDLE_NAME(Receiver, Sender); + +FEDERATED_CONNECTION_BUNDLE_CTOR_SIGNATURE(Receiver, Sender) { + FEDERATED_CONNECTION_BUNDLE_CTOR_PREAMBLE(); + CoapUdpIpChannel_ctor(&self->channel, parent->env, REMOTE_ADDRESS, REMOTE_PROTOCOL_FAMILY); + FEDERATED_CONNECTION_BUNDLE_CALL_CTOR(); + INITIALIZE_FEDERATED_INPUT_CONNECTION(Receiver, in, deserialize_msg_t); +} + +typedef struct { + Reactor super; + CHILD_REACTOR_INSTANCE(Receiver, receiver, 1); + FEDERATED_CONNECTION_BUNDLE_INSTANCE(Receiver, Sender); + FEDERATE_BOOKKEEPING_INSTANCES(1); + CHILD_INPUT_SOURCES(receiver, in, 1, 1, 0); +} MainRecv; + +REACTOR_CTOR_SIGNATURE(MainRecv) { + REACTOR_CTOR(MainRecv); + FEDERATE_CTOR_PREAMBLE(); + DEFINE_CHILD_INPUT_ARGS(receiver, in, 1, 1); + INITIALIZE_CHILD_REACTOR_WITH_PARAMETERS(Receiver, receiver, 1, _receiver_in_args[i]); + INITIALIZE_FEDERATED_CONNECTION_BUNDLE(Receiver, Sender); + BUNDLE_REGISTER_DOWNSTREAM(Receiver, Sender, receiver, in); +} + +ENTRY_POINT_FEDERATED(MainRecv, SEC(1), true, true, 1, false) + +void print_ip_addresses(void) { + gnrc_netif_t *netif = gnrc_netif_iter(NULL); + char addr_str[IPV6_ADDR_MAX_STR_LEN]; + + while (netif) { + size_t max_addr_count = 4; + ipv6_addr_t addrs[max_addr_count]; + gnrc_netif_ipv6_addrs_get(netif, addrs, max_addr_count * sizeof(ipv6_addr_t)); + + for (size_t i = 0; i < 2; i++) { + if (ipv6_addr_to_str(addr_str, &addrs[i], sizeof(addr_str))) { + LF_INFO(NET, "IPv6 address: %s", addr_str); + } + } + + netif = gnrc_netif_iter(netif); + } +} + +int main() { + print_ip_addresses(); + lf_start(); + return 0; +} diff --git a/examples/riot/coap_federated/sender/Makefile b/examples/riot/coap_federated/sender/Makefile new file mode 100755 index 00000000..4c586d20 --- /dev/null +++ b/examples/riot/coap_federated/sender/Makefile @@ -0,0 +1,29 @@ +# name of your application +APPLICATION = lf-coap-federated-sender + +# If no BOARD is found in the environment, use this default: +BOARD ?= native + +# Comment this out to disable code in RIOT that does safety checking +# which is not needed in a production environment but helps in the +# development process: +DEVELHELP ?= 1 + +# Change this to 0 show compiler invocation lines by default: +QUIET ?= 1 + +# Enable reactor-uc features +# CFLAGS += -DNETWORK_CHANNEL_TCP_POSIX +CFLAGS += -DNETWORK_CHANNEL_COAP_RIOT +CFLAGS += -DEVENT_QUEUE_SIZE=32 +CFLAGS += -DREACTION_QUEUE_SIZE=32 + +CFLAGS += -DTHREAD_STACKSIZE_DEFAULT=10000 +CFLAGS += -DTHREAD_STACKSIZE_MAIN=10000 +CFLAGS += -DISR_STACKSIZE=10000 + +# Configure CoAP retransmission timeout +CFLAGS+= -DCONFIG_GCOAP_NO_RETRANS_BACKOFF=1 +CFLAGS+= -DCONFIG_COAP_ACK_TIMEOUT_MS=400 + +include $(CURDIR)/../../../../make/riot/riot.mk diff --git a/examples/riot/coap_federated/sender/main.c b/examples/riot/coap_federated/sender/main.c new file mode 100755 index 00000000..a32ff999 --- /dev/null +++ b/examples/riot/coap_federated/sender/main.c @@ -0,0 +1,120 @@ +#include "reactor-uc/reactor-uc.h" +#include "reactor-uc/platform/riot/coap_udp_ip_channel.h" + +#define REMOTE_ADDRESS "fe80::2882:1bff:fe2d:1362" +#define REMOTE_PROTOCOL_FAMILY AF_INET6 + +typedef struct { + int size; + char msg[512]; +} lf_msg_t; + +size_t serialize_msg_t(const void *user_struct, size_t user_struct_size, unsigned char *msg_buf) { + (void)user_struct_size; + const lf_msg_t *msg = user_struct; + + memcpy(msg_buf, &msg->size, sizeof(msg->size)); + memcpy(msg_buf + sizeof(msg->size), msg->msg, msg->size); + + return sizeof(msg->size) + msg->size; +} + +DEFINE_TIMER_STRUCT(Sender, t, 1, 0) +DEFINE_TIMER_CTOR(Sender, t, 1, 0) +DEFINE_REACTION_STRUCT(Sender, r, 1) +DEFINE_REACTION_CTOR(Sender, r, 0) +DEFINE_OUTPUT_STRUCT(Sender, out, 1, lf_msg_t) +DEFINE_OUTPUT_CTOR(Sender, out, 1) + +typedef struct { + Reactor super; + TIMER_INSTANCE(Sender, t); + REACTION_INSTANCE(Sender, r); + PORT_INSTANCE(Sender, out, 1); + REACTOR_BOOKKEEPING_INSTANCES(1, 2, 0); +} Sender; + +DEFINE_REACTION_BODY(Sender, r) { + SCOPE_SELF(Sender); + SCOPE_ENV(); + SCOPE_PORT(Sender, out); + + printf("Timer triggered @ %" PRId64 "\n", env->get_elapsed_logical_time(env)); + lf_msg_t val; + strcpy(val.msg, "Hello From Sender"); + val.size = sizeof("Hello From Sender"); + lf_set(out, val); +} + +REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Sender, OutputExternalCtorArgs *out_external) { + REACTOR_CTOR_PREAMBLE(); + REACTOR_CTOR(Sender); + INITIALIZE_REACTION(Sender, r); + INITIALIZE_TIMER(Sender, t, MSEC(0), SEC(1)); + INITIALIZE_OUTPUT(Sender, out, 1, out_external); + + TIMER_REGISTER_EFFECT(self->t, self->r); + PORT_REGISTER_SOURCE(self->out, self->r, 1); +} + +DEFINE_FEDERATED_OUTPUT_CONNECTION(Sender, out, lf_msg_t, 1) + +typedef struct { + FederatedConnectionBundle super; + CoapUdpIpChannel channel; + FEDERATED_OUTPUT_CONNECTION_INSTANCE(Sender, out); + FEDERATED_CONNECTION_BUNDLE_BOOKKEEPING_INSTANCES(0, 1); +} FEDERATED_CONNECTION_BUNDLE_NAME(Sender, Receiver); + +FEDERATED_CONNECTION_BUNDLE_CTOR_SIGNATURE(Sender, Receiver) { + FEDERATED_CONNECTION_BUNDLE_CTOR_PREAMBLE(); + CoapUdpIpChannel_ctor(&self->channel, parent->env, REMOTE_ADDRESS, REMOTE_PROTOCOL_FAMILY); + FEDERATED_CONNECTION_BUNDLE_CALL_CTOR(); + INITIALIZE_FEDERATED_OUTPUT_CONNECTION(Sender, out, serialize_msg_t); +} + +// Reactor main +typedef struct { + Reactor super; + CHILD_REACTOR_INSTANCE(Sender, sender, 1); + FEDERATED_CONNECTION_BUNDLE_INSTANCE(Sender, Receiver); + FEDERATE_BOOKKEEPING_INSTANCES(1); + CHILD_OUTPUT_CONNECTIONS(sender, out, 1, 1, 1); + CHILD_OUTPUT_EFFECTS(sender, out, 1, 1, 0); + CHILD_OUTPUT_OBSERVERS(sender, out, 1, 1, 0); +} MainSender; + +REACTOR_CTOR_SIGNATURE(MainSender) { + REACTOR_CTOR(MainSender); + FEDERATE_CTOR_PREAMBLE(); + DEFINE_CHILD_OUTPUT_ARGS(sender, out, 1, 1); + INITIALIZE_CHILD_REACTOR_WITH_PARAMETERS(Sender, sender, 1, _sender_out_args[i]); + INITIALIZE_FEDERATED_CONNECTION_BUNDLE(Sender, Receiver); + BUNDLE_REGISTER_UPSTREAM(Sender, Receiver, sender, out); +} +ENTRY_POINT_FEDERATED(MainSender, SEC(1), true, false, 1, true) + +void print_ip_addresses(void) { + gnrc_netif_t *netif = gnrc_netif_iter(NULL); + char addr_str[IPV6_ADDR_MAX_STR_LEN]; + + while (netif) { + size_t max_addr_count = 4; + ipv6_addr_t addrs[max_addr_count]; + gnrc_netif_ipv6_addrs_get(netif, addrs, max_addr_count * sizeof(ipv6_addr_t)); + + for (size_t i = 0; i < 2; i++) { + if (ipv6_addr_to_str(addr_str, &addrs[i], sizeof(addr_str))) { + LF_INFO(NET, "IPv6 address: %s", addr_str); + } + } + + netif = gnrc_netif_iter(netif); + } +} + +int main() { + print_ip_addresses(); + lf_start(); + return 0; +} From b3cb4b8c259b231f74c4e9ff2f0ff9faac7966b8 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 10 Dec 2024 22:12:52 +0100 Subject: [PATCH 02/17] Fix after merging main --- .../riot/coap_federated/receiver/Makefile | 7 +- examples/riot/coap_federated/receiver/main.c | 76 ++++++++-------- examples/riot/coap_federated/sender/Makefile | 7 +- examples/riot/coap_federated/sender/main.c | 89 ++++++++++--------- 4 files changed, 93 insertions(+), 86 deletions(-) diff --git a/examples/riot/coap_federated/receiver/Makefile b/examples/riot/coap_federated/receiver/Makefile index d9ac8ac7..41ff1a5f 100755 --- a/examples/riot/coap_federated/receiver/Makefile +++ b/examples/riot/coap_federated/receiver/Makefile @@ -1,6 +1,9 @@ # name of your application APPLICATION = lf-coap-federated-receiver +# This has to be the absolute path to the RIOT base directory: +RIOTBASE ?= $(CURDIR)/../../../../../RIOT + # If no BOARD is found in the environment, use this default: BOARD ?= native @@ -15,8 +18,8 @@ QUIET ?= 1 # Enable reactor-uc features # CFLAGS += -DNETWORK_CHANNEL_TCP_POSIX CFLAGS += -DNETWORK_CHANNEL_COAP_RIOT -CFLAGS += -DEVENT_QUEUE_SIZE=32 -CFLAGS += -DREACTION_QUEUE_SIZE=32 +REACTION_QUEUE_SIZE = 32 +EVENT_QUEUE_SIZE = 32 CFLAGS += -DTHREAD_STACKSIZE_DEFAULT=10000 CFLAGS += -DTHREAD_STACKSIZE_MAIN=10000 diff --git a/examples/riot/coap_federated/receiver/main.c b/examples/riot/coap_federated/receiver/main.c index a4d40b2e..7c6cf763 100755 --- a/examples/riot/coap_federated/receiver/main.c +++ b/examples/riot/coap_federated/receiver/main.c @@ -1,5 +1,5 @@ -#include "reactor-uc/reactor-uc.h" #include "reactor-uc/platform/riot/coap_udp_ip_channel.h" +#include "reactor-uc/reactor-uc.h" #define REMOTE_ADDRESS "fe80::4c48:d8ff:fece:9a93" #define REMOTE_PROTOCOL_FAMILY AF_INET6 @@ -19,71 +19,71 @@ lf_ret_t deserialize_msg_t(void *user_struct, const unsigned char *msg_buf, size return LF_OK; } -DEFINE_REACTION_STRUCT(Receiver, r, 0); -DEFINE_REACTION_CTOR(Receiver, r, 0); -DEFINE_INPUT_STRUCT(Receiver, in, 1, 0, lf_msg_t, 0); -DEFINE_INPUT_CTOR(Receiver, in, 1, 0, lf_msg_t, 0); +LF_DEFINE_REACTION_STRUCT(Receiver, r, 0); +LF_DEFINE_REACTION_CTOR(Receiver, r, 0); +LF_DEFINE_INPUT_STRUCT(Receiver, in, 1, 0, lf_msg_t, 0); +LF_DEFINE_INPUT_CTOR(Receiver, in, 1, 0, lf_msg_t, 0); typedef struct { Reactor super; - REACTION_INSTANCE(Receiver, r); - PORT_INSTANCE(Receiver, in, 1); + LF_REACTION_INSTANCE(Receiver, r); + LF_PORT_INSTANCE(Receiver, in, 1); int cnt; - REACTOR_BOOKKEEPING_INSTANCES(1, 1, 0); + LF_REACTOR_BOOKKEEPING_INSTANCES(1, 1, 0); } Receiver; -DEFINE_REACTION_BODY(Receiver, r) { - SCOPE_SELF(Receiver); - SCOPE_ENV(); - SCOPE_PORT(Receiver, in); +LF_DEFINE_REACTION_BODY(Receiver, r) { + LF_SCOPE_SELF(Receiver); + LF_SCOPE_ENV(); + LF_SCOPE_PORT(Receiver, in); printf("Input triggered @ %" PRId64 " with %s size %d\n", env->get_elapsed_logical_time(env), in->value.msg, in->value.size); } -REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Receiver, InputExternalCtorArgs *in_external) { - REACTOR_CTOR_PREAMBLE(); - REACTOR_CTOR(Receiver); - INITIALIZE_REACTION(Receiver, r); - INITIALIZE_INPUT(Receiver, in, 1, in_external); +LF_REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Receiver, InputExternalCtorArgs *in_external) { + LF_REACTOR_CTOR_PREAMBLE(); + LF_REACTOR_CTOR(Receiver); + LF_INITIALIZE_REACTION(Receiver, r); + LF_INITIALIZE_INPUT(Receiver, in, 1, in_external); // Register reaction as an effect of in - PORT_REGISTER_EFFECT(self->in, self->r, 1); + LF_PORT_REGISTER_EFFECT(self->in, self->r, 1); } -DEFINE_FEDERATED_INPUT_CONNECTION(Receiver, in, lf_msg_t, 5, MSEC(100), false); +LF_DEFINE_FEDERATED_INPUT_CONNECTION(Receiver, in, lf_msg_t, 5, MSEC(100), false); typedef struct { FederatedConnectionBundle super; CoapUdpIpChannel channel; - FEDERATED_INPUT_CONNECTION_INSTANCE(Receiver, in); - FEDERATED_CONNECTION_BUNDLE_BOOKKEEPING_INSTANCES(1, 0) -} FEDERATED_CONNECTION_BUNDLE_NAME(Receiver, Sender); + LF_FEDERATED_INPUT_CONNECTION_INSTANCE(Receiver, in); + LF_FEDERATED_CONNECTION_BUNDLE_BOOKKEEPING_INSTANCES(1, 0) +} LF_FEDERATED_CONNECTION_BUNDLE_NAME(Receiver, Sender); -FEDERATED_CONNECTION_BUNDLE_CTOR_SIGNATURE(Receiver, Sender) { - FEDERATED_CONNECTION_BUNDLE_CTOR_PREAMBLE(); +LF_FEDERATED_CONNECTION_BUNDLE_CTOR_SIGNATURE(Receiver, Sender) { + LF_FEDERATED_CONNECTION_BUNDLE_CTOR_PREAMBLE(); CoapUdpIpChannel_ctor(&self->channel, parent->env, REMOTE_ADDRESS, REMOTE_PROTOCOL_FAMILY); - FEDERATED_CONNECTION_BUNDLE_CALL_CTOR(); - INITIALIZE_FEDERATED_INPUT_CONNECTION(Receiver, in, deserialize_msg_t); + LF_FEDERATED_CONNECTION_BUNDLE_CALL_CTOR(); + LF_INITIALIZE_FEDERATED_INPUT_CONNECTION(Receiver, in, deserialize_msg_t); } typedef struct { Reactor super; - CHILD_REACTOR_INSTANCE(Receiver, receiver, 1); - FEDERATED_CONNECTION_BUNDLE_INSTANCE(Receiver, Sender); - FEDERATE_BOOKKEEPING_INSTANCES(1); - CHILD_INPUT_SOURCES(receiver, in, 1, 1, 0); + LF_CHILD_REACTOR_INSTANCE(Receiver, receiver, 1); + LF_FEDERATED_CONNECTION_BUNDLE_INSTANCE(Receiver, Sender); + LF_FEDERATE_BOOKKEEPING_INSTANCES(1); + LF_CHILD_INPUT_SOURCES(receiver, in, 1, 1, 0); } MainRecv; -REACTOR_CTOR_SIGNATURE(MainRecv) { - REACTOR_CTOR(MainRecv); - FEDERATE_CTOR_PREAMBLE(); - DEFINE_CHILD_INPUT_ARGS(receiver, in, 1, 1); - INITIALIZE_CHILD_REACTOR_WITH_PARAMETERS(Receiver, receiver, 1, _receiver_in_args[i]); - INITIALIZE_FEDERATED_CONNECTION_BUNDLE(Receiver, Sender); - BUNDLE_REGISTER_DOWNSTREAM(Receiver, Sender, receiver, in); +LF_REACTOR_CTOR_SIGNATURE(MainRecv) { + LF_REACTOR_CTOR(MainRecv); + LF_FEDERATE_CTOR_PREAMBLE(); + LF_DEFINE_CHILD_INPUT_ARGS(receiver, in, 1, 1); + LF_INITIALIZE_CHILD_REACTOR_WITH_PARAMETERS(Receiver, receiver, 1, _receiver_in_args[i]); + LF_INITIALIZE_FEDERATED_CONNECTION_BUNDLE(Receiver, Sender); + LF_BUNDLE_REGISTER_DOWNSTREAM(Receiver, Sender, receiver, in); } -ENTRY_POINT_FEDERATED(MainRecv, SEC(1), true, true, 1, false) +LF_ENTRY_POINT_FEDERATED(MainRecv, SEC(1), true, true, 1, false) void print_ip_addresses(void) { gnrc_netif_t *netif = gnrc_netif_iter(NULL); diff --git a/examples/riot/coap_federated/sender/Makefile b/examples/riot/coap_federated/sender/Makefile index 4c586d20..276ff149 100755 --- a/examples/riot/coap_federated/sender/Makefile +++ b/examples/riot/coap_federated/sender/Makefile @@ -1,6 +1,9 @@ # name of your application APPLICATION = lf-coap-federated-sender +# This has to be the absolute path to the RIOT base directory: +RIOTBASE ?= $(CURDIR)/../../../../../RIOT + # If no BOARD is found in the environment, use this default: BOARD ?= native @@ -15,8 +18,8 @@ QUIET ?= 1 # Enable reactor-uc features # CFLAGS += -DNETWORK_CHANNEL_TCP_POSIX CFLAGS += -DNETWORK_CHANNEL_COAP_RIOT -CFLAGS += -DEVENT_QUEUE_SIZE=32 -CFLAGS += -DREACTION_QUEUE_SIZE=32 +REACTION_QUEUE_SIZE = 32 +EVENT_QUEUE_SIZE = 32 CFLAGS += -DTHREAD_STACKSIZE_DEFAULT=10000 CFLAGS += -DTHREAD_STACKSIZE_MAIN=10000 diff --git a/examples/riot/coap_federated/sender/main.c b/examples/riot/coap_federated/sender/main.c index a32ff999..5023157e 100755 --- a/examples/riot/coap_federated/sender/main.c +++ b/examples/riot/coap_federated/sender/main.c @@ -19,25 +19,25 @@ size_t serialize_msg_t(const void *user_struct, size_t user_struct_size, unsigne return sizeof(msg->size) + msg->size; } -DEFINE_TIMER_STRUCT(Sender, t, 1, 0) -DEFINE_TIMER_CTOR(Sender, t, 1, 0) -DEFINE_REACTION_STRUCT(Sender, r, 1) -DEFINE_REACTION_CTOR(Sender, r, 0) -DEFINE_OUTPUT_STRUCT(Sender, out, 1, lf_msg_t) -DEFINE_OUTPUT_CTOR(Sender, out, 1) +LF_DEFINE_TIMER_STRUCT(Sender, t, 1, 0) +LF_DEFINE_TIMER_CTOR(Sender, t, 1, 0) +LF_DEFINE_REACTION_STRUCT(Sender, r, 1) +LF_DEFINE_REACTION_CTOR(Sender, r, 0) +LF_DEFINE_OUTPUT_STRUCT(Sender, out, 1, lf_msg_t) +LF_DEFINE_OUTPUT_CTOR(Sender, out, 1) typedef struct { Reactor super; - TIMER_INSTANCE(Sender, t); - REACTION_INSTANCE(Sender, r); - PORT_INSTANCE(Sender, out, 1); - REACTOR_BOOKKEEPING_INSTANCES(1, 2, 0); + LF_TIMER_INSTANCE(Sender, t); + LF_REACTION_INSTANCE(Sender, r); + LF_PORT_INSTANCE(Sender, out, 1); + LF_REACTOR_BOOKKEEPING_INSTANCES(1, 2, 0); } Sender; -DEFINE_REACTION_BODY(Sender, r) { - SCOPE_SELF(Sender); - SCOPE_ENV(); - SCOPE_PORT(Sender, out); +LF_DEFINE_REACTION_BODY(Sender, r) { + LF_SCOPE_SELF(Sender); + LF_SCOPE_ENV(); + LF_SCOPE_PORT(Sender, out); printf("Timer triggered @ %" PRId64 "\n", env->get_elapsed_logical_time(env)); lf_msg_t val; @@ -46,53 +46,54 @@ DEFINE_REACTION_BODY(Sender, r) { lf_set(out, val); } -REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Sender, OutputExternalCtorArgs *out_external) { - REACTOR_CTOR_PREAMBLE(); - REACTOR_CTOR(Sender); - INITIALIZE_REACTION(Sender, r); - INITIALIZE_TIMER(Sender, t, MSEC(0), SEC(1)); - INITIALIZE_OUTPUT(Sender, out, 1, out_external); +LF_REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Sender, OutputExternalCtorArgs *out_external) { + LF_REACTOR_CTOR_PREAMBLE(); + LF_REACTOR_CTOR(Sender); + LF_INITIALIZE_REACTION(Sender, r); + LF_INITIALIZE_TIMER(Sender, t, MSEC(0), SEC(1)); + LF_INITIALIZE_OUTPUT(Sender, out, 1, out_external); - TIMER_REGISTER_EFFECT(self->t, self->r); - PORT_REGISTER_SOURCE(self->out, self->r, 1); + LF_TIMER_REGISTER_EFFECT(self->t, self->r); + LF_PORT_REGISTER_SOURCE(self->out, self->r, 1); } -DEFINE_FEDERATED_OUTPUT_CONNECTION(Sender, out, lf_msg_t, 1) +LF_DEFINE_FEDERATED_OUTPUT_CONNECTION(Sender, out, lf_msg_t, 1) typedef struct { FederatedConnectionBundle super; CoapUdpIpChannel channel; - FEDERATED_OUTPUT_CONNECTION_INSTANCE(Sender, out); - FEDERATED_CONNECTION_BUNDLE_BOOKKEEPING_INSTANCES(0, 1); -} FEDERATED_CONNECTION_BUNDLE_NAME(Sender, Receiver); + LF_FEDERATED_OUTPUT_CONNECTION_INSTANCE(Sender, out); + LF_FEDERATED_CONNECTION_BUNDLE_BOOKKEEPING_INSTANCES(0, 1); +} LF_FEDERATED_CONNECTION_BUNDLE_NAME(Sender, Receiver); -FEDERATED_CONNECTION_BUNDLE_CTOR_SIGNATURE(Sender, Receiver) { - FEDERATED_CONNECTION_BUNDLE_CTOR_PREAMBLE(); +LF_FEDERATED_CONNECTION_BUNDLE_CTOR_SIGNATURE(Sender, Receiver) { + LF_FEDERATED_CONNECTION_BUNDLE_CTOR_PREAMBLE(); CoapUdpIpChannel_ctor(&self->channel, parent->env, REMOTE_ADDRESS, REMOTE_PROTOCOL_FAMILY); - FEDERATED_CONNECTION_BUNDLE_CALL_CTOR(); - INITIALIZE_FEDERATED_OUTPUT_CONNECTION(Sender, out, serialize_msg_t); + LF_FEDERATED_CONNECTION_BUNDLE_CALL_CTOR(); + LF_INITIALIZE_FEDERATED_OUTPUT_CONNECTION(Sender, out, serialize_msg_t); } // Reactor main typedef struct { Reactor super; - CHILD_REACTOR_INSTANCE(Sender, sender, 1); - FEDERATED_CONNECTION_BUNDLE_INSTANCE(Sender, Receiver); - FEDERATE_BOOKKEEPING_INSTANCES(1); - CHILD_OUTPUT_CONNECTIONS(sender, out, 1, 1, 1); - CHILD_OUTPUT_EFFECTS(sender, out, 1, 1, 0); - CHILD_OUTPUT_OBSERVERS(sender, out, 1, 1, 0); + LF_CHILD_REACTOR_INSTANCE(Sender, sender, 1); + LF_FEDERATED_CONNECTION_BUNDLE_INSTANCE(Sender, Receiver); + LF_FEDERATE_BOOKKEEPING_INSTANCES(1); + LF_CHILD_OUTPUT_CONNECTIONS(sender, out, 1, 1, 1); + LF_CHILD_OUTPUT_EFFECTS(sender, out, 1, 1, 0); + LF_CHILD_OUTPUT_OBSERVERS(sender, out, 1, 1, 0); } MainSender; -REACTOR_CTOR_SIGNATURE(MainSender) { - REACTOR_CTOR(MainSender); - FEDERATE_CTOR_PREAMBLE(); - DEFINE_CHILD_OUTPUT_ARGS(sender, out, 1, 1); - INITIALIZE_CHILD_REACTOR_WITH_PARAMETERS(Sender, sender, 1, _sender_out_args[i]); - INITIALIZE_FEDERATED_CONNECTION_BUNDLE(Sender, Receiver); - BUNDLE_REGISTER_UPSTREAM(Sender, Receiver, sender, out); +LF_REACTOR_CTOR_SIGNATURE(MainSender) { + LF_REACTOR_CTOR(MainSender); + LF_FEDERATE_CTOR_PREAMBLE(); + LF_DEFINE_CHILD_OUTPUT_ARGS(sender, out, 1, 1); + LF_INITIALIZE_CHILD_REACTOR_WITH_PARAMETERS(Sender, sender, 1, _sender_out_args[i]); + LF_INITIALIZE_FEDERATED_CONNECTION_BUNDLE(Sender, Receiver); + LF_BUNDLE_REGISTER_UPSTREAM(Sender, Receiver, sender, out); } -ENTRY_POINT_FEDERATED(MainSender, SEC(1), true, false, 1, true) + +LF_ENTRY_POINT_FEDERATED(MainSender, SEC(1), true, false, 1, true) void print_ip_addresses(void) { gnrc_netif_t *netif = gnrc_netif_iter(NULL); From b17d4d8bfb46b58108291243b00f2e9d817cef22 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 11 Dec 2024 18:29:16 +0100 Subject: [PATCH 03/17] Improve coap channel --- src/platform/riot/coap_udp_ip_channel.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/platform/riot/coap_udp_ip_channel.c b/src/platform/riot/coap_udp_ip_channel.c index 89a5a2e7..6dd5c2af 100644 --- a/src/platform/riot/coap_udp_ip_channel.c +++ b/src/platform/riot/coap_udp_ip_channel.c @@ -6,6 +6,7 @@ #include "net/gcoap.h" #include "net/sock/util.h" #include +#include #define COAP_UDP_IP_CHANNEL_ERR(fmt, ...) LF_ERR(NET, "CoapUdpIpChannel: " fmt, ##__VA_ARGS__) #define COAP_UDP_IP_CHANNEL_WARN(fmt, ...) LF_WARN(NET, "CoapUdpIpChannel: " fmt, ##__VA_ARGS__) @@ -26,7 +27,9 @@ static void _CoapUdpIpChannel_update_state(CoapUdpIpChannel *self, NetworkChanne NetworkChannelState old_state = self->state; // Update the state of the channel to its new state + mutex_lock(&self->state_mutex); self->state = new_state; + mutex_unlock(&self->state_mutex); // Inform runtime about new state if it changed from or to NETWORK_CHANNEL_STATE_CONNECTED if ((old_state == NETWORK_CHANNEL_STATE_CONNECTED && new_state != NETWORK_CHANNEL_STATE_CONNECTED) || @@ -40,7 +43,8 @@ static void _CoapUdpIpChannel_update_state_if_not(CoapUdpIpChannel *self, Networ // Update the state of the channel itself mutex_lock(&self->state_mutex); if (self->state != if_not) { - COAP_UDP_IP_CHANNEL_DEBUG("Update state: %d => %d\n", self->state, new_state); + COAP_UDP_IP_CHANNEL_DEBUG("Update state: %s => %s\n", NetworkChannel_state_to_string(self->state), + NetworkChannel_state_to_string(new_state)); self->state = new_state; } mutex_unlock(&self->state_mutex); @@ -84,10 +88,12 @@ static bool _CoapUdpIpChannel_send_coap_message(sock_udp_ep_t *remote, char *pat coap_hdr_set_type(pdu.hdr, COAP_TYPE_CON); ssize_t bytes_sent = gcoap_req_send(buf, len, remote, NULL, resp_handler, NULL, GCOAP_SOCKET_TYPE_UDP); - COAP_UDP_IP_CHANNEL_DEBUG("Sending %d bytes", bytes_sent); if (bytes_sent > 0) { + COAP_UDP_IP_CHANNEL_DEBUG("Sending %d bytes", bytes_sent); COAP_UDP_IP_CHANNEL_DEBUG("Message sent"); return true; + } else { + COAP_UDP_IP_CHANNEL_ERR("Failed to send CoAP message. errno=", errno); } return false; From d61f3191129e60beccc1743f52bbd20ec62209a3 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 16 Dec 2024 17:47:55 +0100 Subject: [PATCH 04/17] Add connection thread to keep channels connected --- .../riot/coap_federated/receiver/Makefile | 1 + examples/riot/coap_federated/sender/Makefile | 1 + src/platform/riot/coap_udp_ip_channel.c | 75 +++++++++++++++---- 3 files changed, 62 insertions(+), 15 deletions(-) diff --git a/examples/riot/coap_federated/receiver/Makefile b/examples/riot/coap_federated/receiver/Makefile index 41ff1a5f..a14d8b3d 100755 --- a/examples/riot/coap_federated/receiver/Makefile +++ b/examples/riot/coap_federated/receiver/Makefile @@ -28,5 +28,6 @@ CFLAGS += -DISR_STACKSIZE=10000 # Configure CoAP retransmission timeout CFLAGS+= -DCONFIG_GCOAP_NO_RETRANS_BACKOFF=1 CFLAGS+= -DCONFIG_COAP_ACK_TIMEOUT_MS=400 +CFLAGS+= -DCONFIG_COAP_MAX_RETRANSMIT=4 include $(CURDIR)/../../../../make/riot/riot.mk diff --git a/examples/riot/coap_federated/sender/Makefile b/examples/riot/coap_federated/sender/Makefile index 276ff149..ef1de51d 100755 --- a/examples/riot/coap_federated/sender/Makefile +++ b/examples/riot/coap_federated/sender/Makefile @@ -28,5 +28,6 @@ CFLAGS += -DISR_STACKSIZE=10000 # Configure CoAP retransmission timeout CFLAGS+= -DCONFIG_GCOAP_NO_RETRANS_BACKOFF=1 CFLAGS+= -DCONFIG_COAP_ACK_TIMEOUT_MS=400 +CFLAGS+= -DCONFIG_COAP_MAX_RETRANSMIT=4 include $(CURDIR)/../../../../make/riot/riot.mk diff --git a/src/platform/riot/coap_udp_ip_channel.c b/src/platform/riot/coap_udp_ip_channel.c index 6dd5c2af..4f2e47f9 100644 --- a/src/platform/riot/coap_udp_ip_channel.c +++ b/src/platform/riot/coap_udp_ip_channel.c @@ -5,20 +5,19 @@ #include "net/gcoap.h" #include "net/sock/util.h" +#include "thread.h" #include -#include #define COAP_UDP_IP_CHANNEL_ERR(fmt, ...) LF_ERR(NET, "CoapUdpIpChannel: " fmt, ##__VA_ARGS__) #define COAP_UDP_IP_CHANNEL_WARN(fmt, ...) LF_WARN(NET, "CoapUdpIpChannel: " fmt, ##__VA_ARGS__) #define COAP_UDP_IP_CHANNEL_INFO(fmt, ...) LF_INFO(NET, "CoapUdpIpChannel: " fmt, ##__VA_ARGS__) #define COAP_UDP_IP_CHANNEL_DEBUG(fmt, ...) LF_DEBUG(NET, "CoapUdpIpChannel: " fmt, ##__VA_ARGS__) +char _connection_thread_stack[THREAD_STACKSIZE_MAIN]; +int _connection_thread_pid; static bool _is_globals_initialized = false; static Environment *_env; -// Forward declarations -static lf_ret_t _CoapUdpIpChannel_client_send_connect_message(CoapUdpIpChannel *self); - static void _CoapUdpIpChannel_update_state(CoapUdpIpChannel *self, NetworkChannelState new_state) { COAP_UDP_IP_CHANNEL_DEBUG("Update state: %s => %s\n", NetworkChannel_state_to_string(self->state), NetworkChannel_state_to_string(new_state)); @@ -36,6 +35,13 @@ static void _CoapUdpIpChannel_update_state(CoapUdpIpChannel *self, NetworkChanne (old_state != NETWORK_CHANNEL_STATE_CONNECTED && new_state == NETWORK_CHANNEL_STATE_CONNECTED)) { _env->platform->new_async_event(_env->platform); } + + // Let connection thread evaluate new state of this channel + msg_t msg = { + .type = 0, + .content.ptr = self, + }; + msg_try_send(&msg, _connection_thread_pid); } static void _CoapUdpIpChannel_update_state_if_not(CoapUdpIpChannel *self, NetworkChannelState new_state, @@ -76,7 +82,6 @@ static CoapUdpIpChannel *_CoapUdpIpChannel_get_coap_channel_by_remote(const sock } COAP_UDP_IP_CHANNEL_ERR("Channel not found by socket"); - return NULL; } @@ -90,12 +95,11 @@ static bool _CoapUdpIpChannel_send_coap_message(sock_udp_ep_t *remote, char *pat ssize_t bytes_sent = gcoap_req_send(buf, len, remote, NULL, resp_handler, NULL, GCOAP_SOCKET_TYPE_UDP); if (bytes_sent > 0) { COAP_UDP_IP_CHANNEL_DEBUG("Sending %d bytes", bytes_sent); - COAP_UDP_IP_CHANNEL_DEBUG("Message sent"); + COAP_UDP_IP_CHANNEL_DEBUG("CoAP Message sent"); return true; - } else { - COAP_UDP_IP_CHANNEL_ERR("Failed to send CoAP message. errno=", errno); } + COAP_UDP_IP_CHANNEL_ERR("Failed to send CoAP message"); return false; } @@ -129,10 +133,11 @@ static bool _CoapUdpIpChannel_send_coap_message_with_payload(CoapUdpIpChannel *s ssize_t bytes_sent = gcoap_req_send(self->write_buffer, len, remote, NULL, resp_handler, NULL, GCOAP_SOCKET_TYPE_UDP); COAP_UDP_IP_CHANNEL_DEBUG("Sending %d bytes", bytes_sent); if (bytes_sent > 0) { - COAP_UDP_IP_CHANNEL_DEBUG("Message sent"); + COAP_UDP_IP_CHANNEL_DEBUG("CoAP Message sent"); return true; } + COAP_UDP_IP_CHANNEL_ERR("Failed to send CoAP message"); return false; } @@ -223,11 +228,11 @@ static void _CoapUdpIpChannel_client_open_connection_callback(const gcoap_reques if (memo->state == GCOAP_MEMO_TIMEOUT) { // Failure COAP_UDP_IP_CHANNEL_ERR("TIMEOUT => Try to connect again"); - _CoapUdpIpChannel_client_send_connect_message(self); // Try to connect again + _CoapUdpIpChannel_update_state(self, NETWORK_CHANNEL_STATE_CONNECTION_FAILED); } else if (coap_get_code_class(pdu) != COAP_CLASS_SUCCESS) { // Failure COAP_UDP_IP_CHANNEL_ERR("CONNECTION REJECTED => Try to connect again"); - _CoapUdpIpChannel_client_send_connect_message(self); // Try to connect again + _CoapUdpIpChannel_update_state(self, NETWORK_CHANNEL_STATE_CONNECTION_FAILED); } else { // Success _CoapUdpIpChannel_update_state(self, NETWORK_CHANNEL_STATE_CONNECTED); @@ -260,7 +265,8 @@ static lf_ret_t CoapUdpIpChannel_open_connection(NetworkChannel *untyped_self) { // the connection to us as established. /* Client */ - return _CoapUdpIpChannel_client_send_connect_message(self); + _CoapUdpIpChannel_update_state(self, NETWORK_CHANNEL_STATE_OPEN); + return LF_OK; } static void _CoapUdpIpChannel_client_close_connection_callback(const gcoap_request_memo_t *memo, coap_pkt_t *pdu, @@ -318,9 +324,6 @@ static lf_ret_t CoapUdpIpChannel_send_blocking(NetworkChannel *untyped_self, con if (_CoapUdpIpChannel_get_state(self) == NETWORK_CHANNEL_STATE_CONNECTED) { return LF_OK; - } else { - // Try to connect again - _CoapUdpIpChannel_client_send_connect_message(self); } } @@ -351,6 +354,43 @@ static bool CoapUdpIpChannel_is_connected(NetworkChannel *untyped_self) { return _CoapUdpIpChannel_get_state(self) == NETWORK_CHANNEL_STATE_CONNECTED; } +void *_CoapUdpIpChannel_connection_thread(void *arg) { + (void)arg; + msg_t m; + + while (true) { + msg_receive(&m); + + CoapUdpIpChannel *self = m.content.ptr; + + switch (self->state) { + case NETWORK_CHANNEL_STATE_OPEN: { + /* try to connect */ + _CoapUdpIpChannel_client_send_connect_message(self); + } break; + + case NETWORK_CHANNEL_STATE_CONNECTION_IN_PROGRESS: + /* nothing to do */ + break; + + case NETWORK_CHANNEL_STATE_LOST_CONNECTION: + case NETWORK_CHANNEL_STATE_CONNECTION_FAILED: { + /* try to reconnect */ + _CoapUdpIpChannel_client_send_connect_message(self); + } break; + + case NETWORK_CHANNEL_STATE_CONNECTED: + break; + + case NETWORK_CHANNEL_STATE_UNINITIALIZED: + case NETWORK_CHANNEL_STATE_CLOSED: + break; + } + } + + return NULL; +} + void CoapUdpIpChannel_ctor(CoapUdpIpChannel *self, Environment *env, const char *remote_address, int remote_protocol_family) { assert(self != NULL); @@ -366,6 +406,11 @@ void CoapUdpIpChannel_ctor(CoapUdpIpChannel *self, Environment *env, const char // Initialize coap server gcoap_register_listener(&_listener); + + // Create connection thread + _connection_thread_pid = + thread_create(_connection_thread_stack, sizeof(_connection_thread_stack), THREAD_PRIORITY_MAIN - 1, 0, + _CoapUdpIpChannel_connection_thread, NULL, "coap_connection_thread"); } // Super fields From 67c7007eed6d0956976b51e48c2b6d37a4a19df1 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 16 Dec 2024 19:34:52 +0100 Subject: [PATCH 05/17] Fix riot critical section? --- examples/riot/coap_federated/receiver/main.c | 10 +++++----- src/platform/riot/coap_udp_ip_channel.c | 3 ++- src/platform/riot/riot.c | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/riot/coap_federated/receiver/main.c b/examples/riot/coap_federated/receiver/main.c index 7c6cf763..4295ba86 100755 --- a/examples/riot/coap_federated/receiver/main.c +++ b/examples/riot/coap_federated/receiver/main.c @@ -19,10 +19,10 @@ lf_ret_t deserialize_msg_t(void *user_struct, const unsigned char *msg_buf, size return LF_OK; } -LF_DEFINE_REACTION_STRUCT(Receiver, r, 0); -LF_DEFINE_REACTION_CTOR(Receiver, r, 0); -LF_DEFINE_INPUT_STRUCT(Receiver, in, 1, 0, lf_msg_t, 0); -LF_DEFINE_INPUT_CTOR(Receiver, in, 1, 0, lf_msg_t, 0); +LF_DEFINE_REACTION_STRUCT(Receiver, r, 0) +LF_DEFINE_REACTION_CTOR(Receiver, r, 0) +LF_DEFINE_INPUT_STRUCT(Receiver, in, 1, 0, lf_msg_t, 0) +LF_DEFINE_INPUT_CTOR(Receiver, in, 1, 0, lf_msg_t, 0) typedef struct { Reactor super; @@ -50,7 +50,7 @@ LF_REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Receiver, InputExternalCtorArgs *in_ex LF_PORT_REGISTER_EFFECT(self->in, self->r, 1); } -LF_DEFINE_FEDERATED_INPUT_CONNECTION(Receiver, in, lf_msg_t, 5, MSEC(100), false); +LF_DEFINE_FEDERATED_INPUT_CONNECTION(Receiver, in, lf_msg_t, 5, MSEC(100), false) typedef struct { FederatedConnectionBundle super; diff --git a/src/platform/riot/coap_udp_ip_channel.c b/src/platform/riot/coap_udp_ip_channel.c index 4f2e47f9..0c15f0b7 100644 --- a/src/platform/riot/coap_udp_ip_channel.c +++ b/src/platform/riot/coap_udp_ip_channel.c @@ -14,7 +14,7 @@ #define COAP_UDP_IP_CHANNEL_DEBUG(fmt, ...) LF_DEBUG(NET, "CoapUdpIpChannel: " fmt, ##__VA_ARGS__) char _connection_thread_stack[THREAD_STACKSIZE_MAIN]; -int _connection_thread_pid; +int _connection_thread_pid = 0; static bool _is_globals_initialized = false; static Environment *_env; @@ -355,6 +355,7 @@ static bool CoapUdpIpChannel_is_connected(NetworkChannel *untyped_self) { } void *_CoapUdpIpChannel_connection_thread(void *arg) { + COAP_UDP_IP_CHANNEL_DEBUG("Start connection thread"); (void)arg; msg_t m; diff --git a/src/platform/riot/riot.c b/src/platform/riot/riot.c index 8b31c71a..ca7d6956 100644 --- a/src/platform/riot/riot.c +++ b/src/platform/riot/riot.c @@ -64,12 +64,12 @@ lf_ret_t PlatformRiot_wait_for(Platform *self, interval_t duration) { void PlatformRiot_leave_critical_section(Platform *self) { PlatformRiot *p = (PlatformRiot *)self; - p->irq_mask = irq_disable(); + irq_restore(p->irq_mask); } void PlatformRiot_enter_critical_section(Platform *self) { PlatformRiot *p = (PlatformRiot *)self; - irq_restore(p->irq_mask); + p->irq_mask = irq_disable(); } void PlatformRiot_new_async_event(Platform *self) { mutex_unlock(&((PlatformRiot *)self)->lock); } From 328eafb3b44e6e64b1c33e0d89afa612b0123bb4 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Thu, 19 Dec 2024 16:32:24 +0100 Subject: [PATCH 06/17] Remove critical section in LF_ENTRY_POINT_FEDERATED for now --- include/reactor-uc/macros.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/reactor-uc/macros.h b/include/reactor-uc/macros.h index 8f5801c0..08b26e02 100644 --- a/include/reactor-uc/macros.h +++ b/include/reactor-uc/macros.h @@ -672,12 +672,10 @@ typedef struct FederatedInputConnection FederatedInputConnection; env.scheduler->leader = IsLeader; \ env.has_async_events = HasInputs; \ \ - env.enter_critical_section(&env); \ FederateName##_ctor(&main_reactor, NULL, &env); \ env.net_bundles_size = NumBundles; \ env.net_bundles = (FederatedConnectionBundle **)&main_reactor._bundles; \ env.assemble(&env); \ - env.leave_critical_section(&env); \ env.start(&env); \ lf_exit(); \ } From c815f905fe9ba3d46e55838ac19c75f57bb7d45e Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Thu, 19 Dec 2024 17:07:12 +0100 Subject: [PATCH 07/17] Print ip address if channel is not found --- src/platform/riot/coap_udp_ip_channel.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/platform/riot/coap_udp_ip_channel.c b/src/platform/riot/coap_udp_ip_channel.c index 0c15f0b7..07e11fb6 100644 --- a/src/platform/riot/coap_udp_ip_channel.c +++ b/src/platform/riot/coap_udp_ip_channel.c @@ -81,7 +81,10 @@ static CoapUdpIpChannel *_CoapUdpIpChannel_get_coap_channel_by_remote(const sock } } - COAP_UDP_IP_CHANNEL_ERR("Channel not found by socket"); + char remote_addr_str[IPV6_ADDR_MAX_STR_LEN]; + sock_udp_ep_fmt(remote, remote_addr_str, NULL); + + COAP_UDP_IP_CHANNEL_ERR("Channel not found by socket (addr=%s)", remote_addr_str); return NULL; } From da658395cdb45222ea7891a76efdffa2d9b22119 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 7 Jan 2025 18:18:04 +0100 Subject: [PATCH 08/17] Add readme explaining how to run RIOT examples --- examples/riot/README.md | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 examples/riot/README.md diff --git a/examples/riot/README.md b/examples/riot/README.md new file mode 100644 index 00000000..5aefa88e --- /dev/null +++ b/examples/riot/README.md @@ -0,0 +1,53 @@ +# RIOT Examples + +This doc explains how to compile and run the various RIOT OS examples. + +## Setup RIOT Environment + +Make sure that the environment variable `RIOTBASE` points to a `RIOT` codebase. + +## Build and Run + +### Blinky + +```shell +cd examples/riot/blinky +make BOARD=native all term +``` + +### Hello + +```shell +cd examples/riot/hello +make BOARD=native all term +``` + +### CoAP Federated + +The federated example using CoAP channels needs to be run using 2 terminals. +Make sure to set the `PORT` environment variable to the correct `tap` interface such as `tap0` or `tap1` as can be seen in the code below. + +#### Preparation + +```shell +# Setup tap interfaces for communication on the (linux) host +sudo $RIOTBASE/dist/tools/tapsetup/tapsetup +``` + +#### Terminal 1 + +Start the `sender` federated program to sends out a message to the `receiver` once the connection is established. + +```shell +cd examples/riot/coap_federated/sender +make BOARD=native PORT=tap0 all term +``` + +#### Terminal 2 + +Start the `receiver` federated program to receive the message from the `sender`. + +```shell +cd examples/riot/coap_federated/receiver +make BOARD=native PORT=tap1 all term +``` From 3a462ea26e1c32c418f1660df50ad119af8986aa Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 7 Jan 2025 18:22:09 +0100 Subject: [PATCH 09/17] Fix readme example paths --- examples/riot/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/riot/README.md b/examples/riot/README.md index 5aefa88e..a159453e 100644 --- a/examples/riot/README.md +++ b/examples/riot/README.md @@ -11,14 +11,14 @@ Make sure that the environment variable `RIOTBASE` points to a `RIOT` codebase. ### Blinky ```shell -cd examples/riot/blinky +cd blinky make BOARD=native all term ``` ### Hello ```shell -cd examples/riot/hello +cd hello make BOARD=native all term ``` @@ -39,7 +39,7 @@ sudo $RIOTBASE/dist/tools/tapsetup/tapsetup Start the `sender` federated program to sends out a message to the `receiver` once the connection is established. ```shell -cd examples/riot/coap_federated/sender +cd coap_federated/sender make BOARD=native PORT=tap0 all term ``` @@ -48,6 +48,6 @@ make BOARD=native PORT=tap0 all term Start the `receiver` federated program to receive the message from the `sender`. ```shell -cd examples/riot/coap_federated/receiver +cd coap_federated/receiver make BOARD=native PORT=tap1 all term ``` From 6554503fc44615b9e6f5295fdd6ffa252d97a33b Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 7 Jan 2025 20:05:02 +0100 Subject: [PATCH 10/17] Improve the readme for the examples --- examples/riot/README.md | 39 +++++++++++++++---- .../riot/coap_federated/receiver/Makefile | 16 ++++++-- examples/riot/coap_federated/receiver/main.c | 8 +++- examples/riot/coap_federated/sender/Makefile | 16 ++++++-- examples/riot/coap_federated/sender/main.c | 8 +++- 5 files changed, 72 insertions(+), 15 deletions(-) diff --git a/examples/riot/README.md b/examples/riot/README.md index a159453e..7ec1559b 100644 --- a/examples/riot/README.md +++ b/examples/riot/README.md @@ -29,25 +29,50 @@ Make sure to set the `PORT` environment variable to the correct `tap` interface #### Preparation +First you need to create the `tap` interfaces so that the `sender` and `receiver` application can communicate through the (linux) host. + ```shell -# Setup tap interfaces for communication on the (linux) host sudo $RIOTBASE/dist/tools/tapsetup/tapsetup ``` -#### Terminal 1 +#### Sender -Start the `sender` federated program to sends out a message to the `receiver` once the connection is established. +Enter the directory of the `sender` application: ```shell cd coap_federated/sender -make BOARD=native PORT=tap0 all term ``` -#### Terminal 2 +Get the IP address of the `receiver` by specifying the `PORT=tap1` and `ONLY_PRINT_IP=1` environment variables: -Start the `receiver` federated program to receive the message from the `sender`. +```shell +make ONLY_PRINT_IP=1 BOARD=native PORT=tap1 all term +``` + +Start the `sender` federated program to sends out a message to the `receiver` once the connection is established. +Make sure to replace `REMOTE_ADDRESS` with the correct address of the `receiver` and set `PORT=tap0` for the `sender`. + +```shell +make REMOTE_ADDRESS=fe80::8cc3:33ff:febb:1b3 BOARD=native PORT=tap0 all term +``` + +#### Receiver + +Enter the directory of the `receiver` application: ```shell cd coap_federated/receiver -make BOARD=native PORT=tap1 all term +``` + +Get the IP address of the `sender` by specifying the `PORT=tap0` and `ONLY_PRINT_IP=1` environment variables: + +```shell +make ONLY_PRINT_IP=1 BOARD=native PORT=tap0 all term +``` + +Start the `receiver` federated program to receive the message from the `sender`. +Make sure to replace `REMOTE_ADDRESS` with the correct address of the `sender` and set `PORT=tap1` for the `receiver`. + +```shell +make REMOTE_ADDRESS=fe80::44e5:1bff:fee4:dac8 BOARD=native PORT=tap1 all term ``` diff --git a/examples/riot/coap_federated/receiver/Makefile b/examples/riot/coap_federated/receiver/Makefile index a14d8b3d..811db13e 100755 --- a/examples/riot/coap_federated/receiver/Makefile +++ b/examples/riot/coap_federated/receiver/Makefile @@ -26,8 +26,18 @@ CFLAGS += -DTHREAD_STACKSIZE_MAIN=10000 CFLAGS += -DISR_STACKSIZE=10000 # Configure CoAP retransmission timeout -CFLAGS+= -DCONFIG_GCOAP_NO_RETRANS_BACKOFF=1 -CFLAGS+= -DCONFIG_COAP_ACK_TIMEOUT_MS=400 -CFLAGS+= -DCONFIG_COAP_MAX_RETRANSMIT=4 +CFLAGS += -DCONFIG_GCOAP_NO_RETRANS_BACKOFF=1 +CFLAGS += -DCONFIG_COAP_ACK_TIMEOUT_MS=400 +CFLAGS += -DCONFIG_COAP_MAX_RETRANSMIT=4 + +# Set the remote sender address +ifndef REMOTE_ADDRESS +ifndef ONLY_GET_IP + $(error REMOTE_ADDRESS is not defined. Please define it!) +else + CFLAGS += -DONLY_GET_IP=$(ONLY_GET_IP) +endif +endif +CFLAGS += -DREMOTE_ADDRESS=\"$(REMOTE_ADDRESS)\" include $(CURDIR)/../../../../make/riot/riot.mk diff --git a/examples/riot/coap_federated/receiver/main.c b/examples/riot/coap_federated/receiver/main.c index 4295ba86..07a6a94a 100755 --- a/examples/riot/coap_federated/receiver/main.c +++ b/examples/riot/coap_federated/receiver/main.c @@ -1,7 +1,10 @@ #include "reactor-uc/platform/riot/coap_udp_ip_channel.h" #include "reactor-uc/reactor-uc.h" -#define REMOTE_ADDRESS "fe80::4c48:d8ff:fece:9a93" +#ifndef REMOTE_ADDRESS +#define REMOTE_ADDRESS "fe80::44e5:1bff:fee4:dac8" +#endif + #define REMOTE_PROTOCOL_FAMILY AF_INET6 typedef struct { @@ -105,7 +108,10 @@ void print_ip_addresses(void) { } int main() { +#ifdef ONLY_GET_IP print_ip_addresses(); +#else lf_start(); +#endif return 0; } diff --git a/examples/riot/coap_federated/sender/Makefile b/examples/riot/coap_federated/sender/Makefile index ef1de51d..de249657 100755 --- a/examples/riot/coap_federated/sender/Makefile +++ b/examples/riot/coap_federated/sender/Makefile @@ -26,8 +26,18 @@ CFLAGS += -DTHREAD_STACKSIZE_MAIN=10000 CFLAGS += -DISR_STACKSIZE=10000 # Configure CoAP retransmission timeout -CFLAGS+= -DCONFIG_GCOAP_NO_RETRANS_BACKOFF=1 -CFLAGS+= -DCONFIG_COAP_ACK_TIMEOUT_MS=400 -CFLAGS+= -DCONFIG_COAP_MAX_RETRANSMIT=4 +CFLAGS += -DCONFIG_GCOAP_NO_RETRANS_BACKOFF=1 +CFLAGS += -DCONFIG_COAP_ACK_TIMEOUT_MS=400 +CFLAGS += -DCONFIG_COAP_MAX_RETRANSMIT=4 + +# Set the remote receiver address +ifndef REMOTE_ADDRESS +ifndef ONLY_GET_IP + $(error REMOTE_ADDRESS is not defined. Please define it!) +else + CFLAGS += -DONLY_GET_IP=$(ONLY_GET_IP) +endif +endif +CFLAGS += -DREMOTE_ADDRESS=\"$(REMOTE_ADDRESS)\" include $(CURDIR)/../../../../make/riot/riot.mk diff --git a/examples/riot/coap_federated/sender/main.c b/examples/riot/coap_federated/sender/main.c index 5023157e..47c25cbf 100755 --- a/examples/riot/coap_federated/sender/main.c +++ b/examples/riot/coap_federated/sender/main.c @@ -1,7 +1,10 @@ #include "reactor-uc/reactor-uc.h" #include "reactor-uc/platform/riot/coap_udp_ip_channel.h" -#define REMOTE_ADDRESS "fe80::2882:1bff:fe2d:1362" +#ifndef REMOTE_ADDRESS +#define REMOTE_ADDRESS "fe80::8cc3:33ff:febb:1b3" +#endif + #define REMOTE_PROTOCOL_FAMILY AF_INET6 typedef struct { @@ -115,7 +118,10 @@ void print_ip_addresses(void) { } int main() { +#ifdef ONLY_GET_IP print_ip_addresses(); +#else lf_start(); +#endif return 0; } From 7b861ede0c67fe0ffed871aa3201b917f24828d9 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Thu, 9 Jan 2025 15:51:37 +0100 Subject: [PATCH 11/17] Rename only_get_ip to only_print_ip env variable --- examples/riot/coap_federated/receiver/Makefile | 4 ++-- examples/riot/coap_federated/receiver/main.c | 2 +- examples/riot/coap_federated/sender/Makefile | 4 ++-- examples/riot/coap_federated/sender/main.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/riot/coap_federated/receiver/Makefile b/examples/riot/coap_federated/receiver/Makefile index 811db13e..a24a253c 100755 --- a/examples/riot/coap_federated/receiver/Makefile +++ b/examples/riot/coap_federated/receiver/Makefile @@ -32,10 +32,10 @@ CFLAGS += -DCONFIG_COAP_MAX_RETRANSMIT=4 # Set the remote sender address ifndef REMOTE_ADDRESS -ifndef ONLY_GET_IP +ifndef ONLY_PRINT_IP $(error REMOTE_ADDRESS is not defined. Please define it!) else - CFLAGS += -DONLY_GET_IP=$(ONLY_GET_IP) + CFLAGS += -DONLY_PRINT_IP=$(ONLY_PRINT_IP) endif endif CFLAGS += -DREMOTE_ADDRESS=\"$(REMOTE_ADDRESS)\" diff --git a/examples/riot/coap_federated/receiver/main.c b/examples/riot/coap_federated/receiver/main.c index 07a6a94a..9c50219c 100755 --- a/examples/riot/coap_federated/receiver/main.c +++ b/examples/riot/coap_federated/receiver/main.c @@ -108,7 +108,7 @@ void print_ip_addresses(void) { } int main() { -#ifdef ONLY_GET_IP +#ifdef ONLY_PRINT_IP print_ip_addresses(); #else lf_start(); diff --git a/examples/riot/coap_federated/sender/Makefile b/examples/riot/coap_federated/sender/Makefile index de249657..ee01b203 100755 --- a/examples/riot/coap_federated/sender/Makefile +++ b/examples/riot/coap_federated/sender/Makefile @@ -32,10 +32,10 @@ CFLAGS += -DCONFIG_COAP_MAX_RETRANSMIT=4 # Set the remote receiver address ifndef REMOTE_ADDRESS -ifndef ONLY_GET_IP +ifndef ONLY_PRINT_IP $(error REMOTE_ADDRESS is not defined. Please define it!) else - CFLAGS += -DONLY_GET_IP=$(ONLY_GET_IP) + CFLAGS += -DONLY_PRINT_IP=$(ONLY_PRINT_IP) endif endif CFLAGS += -DREMOTE_ADDRESS=\"$(REMOTE_ADDRESS)\" diff --git a/examples/riot/coap_federated/sender/main.c b/examples/riot/coap_federated/sender/main.c index 47c25cbf..9a0e47b3 100755 --- a/examples/riot/coap_federated/sender/main.c +++ b/examples/riot/coap_federated/sender/main.c @@ -118,7 +118,7 @@ void print_ip_addresses(void) { } int main() { -#ifdef ONLY_GET_IP +#ifdef ONLY_PRINT_IP print_ip_addresses(); #else lf_start(); From 23ed0a9c9fb563a61e6b0126fcffb8ea9881f09b Mon Sep 17 00:00:00 2001 From: Lasse Rosenow <10547444+LasseRosenow@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:54:56 +0100 Subject: [PATCH 12/17] Update examples/riot/coap_federated/receiver/Makefile Co-authored-by: erling --- examples/riot/coap_federated/receiver/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/riot/coap_federated/receiver/Makefile b/examples/riot/coap_federated/receiver/Makefile index a24a253c..1844a2ef 100755 --- a/examples/riot/coap_federated/receiver/Makefile +++ b/examples/riot/coap_federated/receiver/Makefile @@ -16,7 +16,6 @@ DEVELHELP ?= 1 QUIET ?= 1 # Enable reactor-uc features -# CFLAGS += -DNETWORK_CHANNEL_TCP_POSIX CFLAGS += -DNETWORK_CHANNEL_COAP_RIOT REACTION_QUEUE_SIZE = 32 EVENT_QUEUE_SIZE = 32 From 21c99c82eb105853fd13c4cadfc3a58a1c8fb959 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Thu, 9 Jan 2025 15:55:32 +0100 Subject: [PATCH 13/17] Also remove tcp_ip from sender --- examples/riot/coap_federated/sender/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/riot/coap_federated/sender/Makefile b/examples/riot/coap_federated/sender/Makefile index ee01b203..6bfe90d3 100755 --- a/examples/riot/coap_federated/sender/Makefile +++ b/examples/riot/coap_federated/sender/Makefile @@ -16,7 +16,6 @@ DEVELHELP ?= 1 QUIET ?= 1 # Enable reactor-uc features -# CFLAGS += -DNETWORK_CHANNEL_TCP_POSIX CFLAGS += -DNETWORK_CHANNEL_COAP_RIOT REACTION_QUEUE_SIZE = 32 EVENT_QUEUE_SIZE = 32 From 975375f4f57eb1fe71cdab864d40dc4600758388 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Thu, 9 Jan 2025 16:10:53 +0100 Subject: [PATCH 14/17] Make makefile more readable --- examples/riot/coap_federated/receiver/Makefile | 17 ++++++++++------- examples/riot/coap_federated/sender/Makefile | 17 ++++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/examples/riot/coap_federated/receiver/Makefile b/examples/riot/coap_federated/receiver/Makefile index 1844a2ef..bb0f9813 100755 --- a/examples/riot/coap_federated/receiver/Makefile +++ b/examples/riot/coap_federated/receiver/Makefile @@ -29,14 +29,17 @@ CFLAGS += -DCONFIG_GCOAP_NO_RETRANS_BACKOFF=1 CFLAGS += -DCONFIG_COAP_ACK_TIMEOUT_MS=400 CFLAGS += -DCONFIG_COAP_MAX_RETRANSMIT=4 -# Set the remote sender address -ifndef REMOTE_ADDRESS -ifndef ONLY_PRINT_IP - $(error REMOTE_ADDRESS is not defined. Please define it!) -else +# Check if ONLY_PRINT_IP is defined +# If ONLY_PRINT_IP is defined the REMOTE_ADDRESS is not needed +ifdef ONLY_PRINT_IP CFLAGS += -DONLY_PRINT_IP=$(ONLY_PRINT_IP) +else + # Check if REMOTE_ADDRESS is defined + ifdef REMOTE_ADDRESS + CFLAGS += -DREMOTE_ADDRESS=\"$(REMOTE_ADDRESS)\" + else + $(error REMOTE_ADDRESS is not defined. Please define it!) + endif endif -endif -CFLAGS += -DREMOTE_ADDRESS=\"$(REMOTE_ADDRESS)\" include $(CURDIR)/../../../../make/riot/riot.mk diff --git a/examples/riot/coap_federated/sender/Makefile b/examples/riot/coap_federated/sender/Makefile index 6bfe90d3..4959672f 100755 --- a/examples/riot/coap_federated/sender/Makefile +++ b/examples/riot/coap_federated/sender/Makefile @@ -29,14 +29,17 @@ CFLAGS += -DCONFIG_GCOAP_NO_RETRANS_BACKOFF=1 CFLAGS += -DCONFIG_COAP_ACK_TIMEOUT_MS=400 CFLAGS += -DCONFIG_COAP_MAX_RETRANSMIT=4 -# Set the remote receiver address -ifndef REMOTE_ADDRESS -ifndef ONLY_PRINT_IP - $(error REMOTE_ADDRESS is not defined. Please define it!) -else +# Check if ONLY_PRINT_IP is defined +# If ONLY_PRINT_IP is defined the REMOTE_ADDRESS is not needed +ifdef ONLY_PRINT_IP CFLAGS += -DONLY_PRINT_IP=$(ONLY_PRINT_IP) +else + # Check if REMOTE_ADDRESS is defined + ifdef REMOTE_ADDRESS + CFLAGS += -DREMOTE_ADDRESS=\"$(REMOTE_ADDRESS)\" + else + $(error REMOTE_ADDRESS is not defined. Please define it!) + endif endif -endif -CFLAGS += -DREMOTE_ADDRESS=\"$(REMOTE_ADDRESS)\" include $(CURDIR)/../../../../make/riot/riot.mk From e3198864d20edb2c1877357acb5dafbeb94ef567 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Thu, 9 Jan 2025 16:44:10 +0100 Subject: [PATCH 15/17] Rewrite make again --- examples/riot/coap_federated/receiver/Makefile | 12 ++++++------ examples/riot/coap_federated/sender/Makefile | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/riot/coap_federated/receiver/Makefile b/examples/riot/coap_federated/receiver/Makefile index bb0f9813..7a6d22cb 100755 --- a/examples/riot/coap_federated/receiver/Makefile +++ b/examples/riot/coap_federated/receiver/Makefile @@ -32,14 +32,14 @@ CFLAGS += -DCONFIG_COAP_MAX_RETRANSMIT=4 # Check if ONLY_PRINT_IP is defined # If ONLY_PRINT_IP is defined the REMOTE_ADDRESS is not needed ifdef ONLY_PRINT_IP + # ONLY_PRINT_IP is defined => Set CFLAGS for it CFLAGS += -DONLY_PRINT_IP=$(ONLY_PRINT_IP) +else ifdef REMOTE_ADDRESS + # REMOTE_ADDRESS is defined => Set CFLAGS for it + CFLAGS += -DREMOTE_ADDRESS=\"$(REMOTE_ADDRESS)\" else - # Check if REMOTE_ADDRESS is defined - ifdef REMOTE_ADDRESS - CFLAGS += -DREMOTE_ADDRESS=\"$(REMOTE_ADDRESS)\" - else - $(error REMOTE_ADDRESS is not defined. Please define it!) - endif + # Neither is defined + $(error Either define REMOTE_ADDRESS or set ONLY_PRINT_IP=1 to print the IP-Address of this device.) endif include $(CURDIR)/../../../../make/riot/riot.mk diff --git a/examples/riot/coap_federated/sender/Makefile b/examples/riot/coap_federated/sender/Makefile index 4959672f..ad03fccd 100755 --- a/examples/riot/coap_federated/sender/Makefile +++ b/examples/riot/coap_federated/sender/Makefile @@ -32,14 +32,14 @@ CFLAGS += -DCONFIG_COAP_MAX_RETRANSMIT=4 # Check if ONLY_PRINT_IP is defined # If ONLY_PRINT_IP is defined the REMOTE_ADDRESS is not needed ifdef ONLY_PRINT_IP + # ONLY_PRINT_IP is defined => Set CFLAGS for it CFLAGS += -DONLY_PRINT_IP=$(ONLY_PRINT_IP) +else ifdef REMOTE_ADDRESS + # REMOTE_ADDRESS is defined => Set CFLAGS for it + CFLAGS += -DREMOTE_ADDRESS=\"$(REMOTE_ADDRESS)\" else - # Check if REMOTE_ADDRESS is defined - ifdef REMOTE_ADDRESS - CFLAGS += -DREMOTE_ADDRESS=\"$(REMOTE_ADDRESS)\" - else - $(error REMOTE_ADDRESS is not defined. Please define it!) - endif + # Neither is defined + $(error Either define REMOTE_ADDRESS or set ONLY_PRINT_IP=1 to print the IP-Address of this device) endif include $(CURDIR)/../../../../make/riot/riot.mk From 2410b6296df52af804e3df4ce9efcbef4f658c4c Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 10 Jan 2025 14:29:24 +0100 Subject: [PATCH 16/17] Add explanation on what ip address to choose --- examples/riot/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/riot/README.md b/examples/riot/README.md index 7ec1559b..cd64d6a9 100644 --- a/examples/riot/README.md +++ b/examples/riot/README.md @@ -45,6 +45,8 @@ cd coap_federated/sender Get the IP address of the `receiver` by specifying the `PORT=tap1` and `ONLY_PRINT_IP=1` environment variables: +*If the program returns more than one IP-Address then select the one that starts with `fe80`*. + ```shell make ONLY_PRINT_IP=1 BOARD=native PORT=tap1 all term ``` @@ -66,6 +68,8 @@ cd coap_federated/receiver Get the IP address of the `sender` by specifying the `PORT=tap0` and `ONLY_PRINT_IP=1` environment variables: +*If the program returns more than one IP-Address then select the one that starts with `fe80`*. + ```shell make ONLY_PRINT_IP=1 BOARD=native PORT=tap0 all term ``` From cd28fc82ae1ba020782710aaa5125e37e167ca96 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 10 Jan 2025 15:24:57 +0100 Subject: [PATCH 17/17] Update README --- examples/riot/README.md | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/examples/riot/README.md b/examples/riot/README.md index cd64d6a9..a81fb92a 100644 --- a/examples/riot/README.md +++ b/examples/riot/README.md @@ -35,7 +35,7 @@ First you need to create the `tap` interfaces so that the `sender` and `receiver sudo $RIOTBASE/dist/tools/tapsetup/tapsetup ``` -#### Sender +#### Get IPv6 address of receiver Enter the directory of the `sender` application: @@ -51,14 +51,11 @@ Get the IP address of the `receiver` by specifying the `PORT=tap1` and `ONLY_PRI make ONLY_PRINT_IP=1 BOARD=native PORT=tap1 all term ``` -Start the `sender` federated program to sends out a message to the `receiver` once the connection is established. -Make sure to replace `REMOTE_ADDRESS` with the correct address of the `receiver` and set `PORT=tap0` for the `sender`. +The resulting program will print out the IPv6 address of `tap1` and terminate. +This address must be used when starting the sender below. -```shell -make REMOTE_ADDRESS=fe80::8cc3:33ff:febb:1b3 BOARD=native PORT=tap0 all term -``` -#### Receiver +#### Get IPv6 address of sender Enter the directory of the `receiver` application: @@ -74,9 +71,26 @@ Get the IP address of the `sender` by specifying the `PORT=tap0` and `ONLY_PRINT make ONLY_PRINT_IP=1 BOARD=native PORT=tap0 all term ``` -Start the `receiver` federated program to receive the message from the `sender`. -Make sure to replace `REMOTE_ADDRESS` with the correct address of the `sender` and set `PORT=tap1` for the `receiver`. +The resulting program will print out the IPv6 address of `tap0` and terminate. +This address must be used when starting the receiver below. + +#### Start the applications + +##### Sender +Start the sender with `PORT=tap0`, make sure to replace `REMOTE_ADDRESS` with +the address of `tap1` that you found above. + +```shell +cd sender +make REMOTE_ADDRESS=fe80::8cc3:33ff:febb:1b3 BOARD=native PORT=tap0 all term +``` + +##### Receiver + +Start the receiver with `PORT=tap1`, make sure to replace `REMOTE_ADDRESS` with +the address of `tap0` that you found above. ```shell +cd receiver make REMOTE_ADDRESS=fe80::44e5:1bff:fee4:dac8 BOARD=native PORT=tap1 all term ```