1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #20378 from benpicco/use-nanocoap_server_auto_init

make use of nanocoap_server_auto_init
This commit is contained in:
Marian Buschsieweke 2024-02-13 18:41:11 +00:00 committed by GitHub
commit d61a468a3e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 9 additions and 88 deletions

View File

@ -38,7 +38,7 @@ QUIET ?= 1
#
USEMODULE += suit suit_transport_coap
USEMODULE += nanocoap_resources
USEMODULE += nanocoap_server_auto_init
# enable VFS transport (only works on boards with external storage)
USEMODULE += suit_transport_vfs

View File

@ -44,13 +44,6 @@
#include "periph/gpio.h"
#endif
#define COAP_INBUF_SIZE (256U)
/* Extend stacksize of nanocoap server thread */
static char _nanocoap_server_stack[THREAD_STACKSIZE_DEFAULT + THREAD_EXTRA_STACKSIZE_PRINTF];
#define NANOCOAP_SERVER_QUEUE_SIZE (8)
static msg_t _nanocoap_server_msg_queue[NANOCOAP_SERVER_QUEUE_SIZE];
#define MAIN_QUEUE_SIZE (8)
static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];
@ -63,21 +56,6 @@ XFA(suit_storage_files_reg, 1) char* _slot1 = VFS_DEFAULT_DATA "/SLOT1.txt";
#endif
#endif
static void *_nanocoap_server_thread(void *arg)
{
(void)arg;
/* nanocoap_server uses gnrc sock which uses gnrc which needs a msg queue */
msg_init_queue(_nanocoap_server_msg_queue, NANOCOAP_SERVER_QUEUE_SIZE);
/* initialize nanocoap server instance */
uint8_t buf[COAP_INBUF_SIZE];
sock_udp_ep_t local = { .port=COAP_PORT, .family=AF_INET6 };
nanocoap_server(&local, buf, sizeof(buf));
return NULL;
}
/* assuming that first button is always BTN0 */
#if defined(MODULE_PERIPH_GPIO_IRQ) && defined(BTN0_PIN)
static void cb(void *arg)
@ -213,12 +191,6 @@ int main(void)
/* initialize suit storage */
suit_storage_init_all();
/* start nanocoap server thread */
thread_create(_nanocoap_server_stack, sizeof(_nanocoap_server_stack),
THREAD_PRIORITY_MAIN - 1,
THREAD_CREATE_STACKTEST,
_nanocoap_server_thread, NULL, "nanocoap server");
/* the shell contains commands that receive packets via GNRC and thus
needs a msg queue */
msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE);

View File

@ -26,7 +26,6 @@ USEMODULE += sock_udp
# Additional networking modules that can be dropped if not needed
USEMODULE += gnrc_icmpv6_echo
USEMODULE += nanocoap_sock
USEMODULE += nanocoap_resources
# include this for printing IP addresses
USEMODULE += shell_cmds_default
@ -44,5 +43,11 @@ CFLAGS += -DCONFIG_INITIATOR=$(CONFIG_INITIATOR)
CONFIG_RESPONDER ?= 1
CFLAGS += -DCONFIG_RESPONDER=$(CONFIG_RESPONDER)
ifeq (1, $(CONFIG_RESPONDER))
USEMODULE += nanocoap_server_auto_init
CFLAGS += -DCONFIG_NANOCOAP_SERVER_BUF_SIZE=512
endif
include $(RIOTBASE)/Makefile.include
include $(RIOTMAKE)/default-radio-settings.inc.mk

View File

@ -30,10 +30,6 @@
static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];
#if IS_ACTIVE(CONFIG_RESPONDER)
static char _nanocoap_server_stack[THREAD_STACKSIZE_MAIN];
#define NANOCOAP_SERVER_QUEUE_SIZE (4)
static msg_t _nanocoap_server_msg_queue[NANOCOAP_SERVER_QUEUE_SIZE];
#define NANOCOAP_BUF_SIZE (512U)
extern int responder_cli_init(void);
extern int responder_cmd(int argc, char **argv);
#endif
@ -54,23 +50,6 @@ static const shell_command_t shell_commands[] = {
{ NULL, NULL, NULL }
};
#if IS_ACTIVE(CONFIG_RESPONDER)
static void *_nanocoap_server_thread(void *arg)
{
(void)arg;
/* nanocoap_server uses gnrc sock which uses gnrc which needs a msg queue */
msg_init_queue(_nanocoap_server_msg_queue, NANOCOAP_SERVER_QUEUE_SIZE);
/* initialize nanocoap server instance */
uint8_t buf[NANOCOAP_BUF_SIZE];
sock_udp_ep_t local = { .port = COAP_PORT, .family = AF_INET6 };
nanocoap_server(&local, buf, sizeof(buf));
return NULL;
}
#endif
int main(void)
{
#if IS_ACTIVE(CONFIG_INITIATOR)
@ -82,12 +61,6 @@ int main(void)
if (responder_cli_init()) {
return -1;
}
/* start nanocoap server thread */
thread_create(_nanocoap_server_stack, sizeof(_nanocoap_server_stack),
THREAD_PRIORITY_MAIN - 1,
THREAD_CREATE_STACKTEST,
_nanocoap_server_thread, NULL, "nanocoap server");
#endif
/* the shell contains commands that receive packets via GNRC and thus

View File

@ -11,9 +11,8 @@ USEMODULE += sock_udp
# Additional networking modules that can be dropped if not needed
USEMODULE += gnrc_icmpv6_echo
# Required for nanocoap server
USEMODULE += nanocoap_sock
USEMODULE += nanocoap_resources
# Enable nanocoap server
USEMODULE += nanocoap_server_auto_init
# include this for printing IP addresses
USEMODULE += shell_cmds_default

View File

@ -28,31 +28,9 @@
#include "riotboot/slot.h"
#include "riotboot/flashwrite.h"
#define COAP_INBUF_SIZE (256U)
/* Extend stacksize of nanocoap server thread */
static char _nanocoap_server_stack[THREAD_STACKSIZE_DEFAULT + THREAD_EXTRA_STACKSIZE_PRINTF];
#define NANOCOAP_SERVER_QUEUE_SIZE (8)
static msg_t _nanocoap_server_msg_queue[NANOCOAP_SERVER_QUEUE_SIZE];
#define MAIN_QUEUE_SIZE (8)
static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];
static void *_nanocoap_server_thread(void *arg)
{
(void)arg;
/* nanocoap_server uses gnrc sock which uses gnrc which needs a msg queue */
msg_init_queue(_nanocoap_server_msg_queue, NANOCOAP_SERVER_QUEUE_SIZE);
/* initialize nanocoap server instance */
uint8_t buf[COAP_INBUF_SIZE];
sock_udp_ep_t local = { .port=COAP_PORT, .family=AF_INET6 };
nanocoap_server(&local, buf, sizeof(buf));
return NULL;
}
static int cmd_print_riotboot_hdr(int argc, char **argv)
{
(void)argc;
@ -111,12 +89,6 @@ int main(void)
cmd_print_current_slot(0, NULL);
cmd_print_riotboot_hdr(0, NULL);
/* start nanocoap server thread */
thread_create(_nanocoap_server_stack, sizeof(_nanocoap_server_stack),
THREAD_PRIORITY_MAIN - 1,
THREAD_CREATE_STACKTEST,
_nanocoap_server_thread, NULL, "nanocoap server");
/* the shell contains commands that receive packets via GNRC and thus
needs a msg queue */
msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE);