Skip to content

Commit

Permalink
examples/nanocoap_tool: add RIOT as a CLI tool
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed May 7, 2024
1 parent db829ac commit bbea0d9
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
47 changes: 47 additions & 0 deletions examples/nanocoap_tool/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# name of your application
APPLICATION = nanocoap_tool

# If no BOARD is found in the environment, use this default:
BOARD ?= native

# This has to be the absolute path to the RIOT base directory:
RIOTBASE ?= $(CURDIR)/../..

# Include packages that pull up and auto-init the link layer.
USEMODULE += netdev_default
USEMODULE += auto_init_gnrc_netif
# Specify the mandatory networking modules for IPv6
USEMODULE += gnrc_ipv6_default
# Additional networking modules that can be dropped if not needed
USEMODULE += gnrc_icmpv6_echo

USEMODULE += auto_init_sock_dns # add fall-back DNS server
USEMODULE += sock_dns # include DNS client
USEMODULE += gnrc_ipv6_nib_dns # include RDNSS option handling

USEMODULE += nanocoap_sock
USEMODULE += nanocoap_vfs

USEMODULE += vfs_default

USEMODULE += shell
USEMODULE += shell_cmds_default

# export the whole fs to RIOT
CFLAGS += -DFS_NATIVE_DIR=\"/\"
# mount it as '/' in RIOT to match the host
CFLAGS += -DCONFIG_NATIVE_MOUNTPOINT=\"/\"
# use the current working directory as download destination
CFLAGS += -DCONFIG_NCGET_DEFAULT_DATA_DIR=\"/proc/self/cwd/\"

# terminate RIOT with main()
CFLAGS += -DCONFIG_CORE_EXIT_WITH_MAIN=1
# don't be verbose
CFLAGS += -DCONFIG_SKIP_BOOT_MSG=1

RIOT_TERMINAL = native
BOARD_WHITELIST = native native64

DEVELHELP ?= 1

include $(RIOTBASE)/Makefile.include
44 changes: 44 additions & 0 deletions examples/nanocoap_tool/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2024 ML!PA Consulting GmbH
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup examples
* @{
*
* @file
* @brief Example application to access RIOT shell commands from Linux
*
* @author Benjamin Valentin <[email protected]>
*
* @}
*/

#include <errno.h>
#include "shell.h"
#include "ztimer.h"

int main(int argc, char **argv)
{
if (argc < 1) {
printf("usage: <command> [args]\n");
return 0;
}

shell_command_handler_t handler = shell_find_handler(NULL, argv[0]);
if (handler == NULL) {
return -EINVAL;
}

/* wait some time for the network to be ready */
ztimer_sleep(ZTIMER_MSEC, 1000);

msg_t msg_queue[8];
msg_init_queue(msg_queue, ARRAY_SIZE(msg_queue));

return handler(argc, argv);
}

0 comments on commit bbea0d9

Please sign in to comment.