-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Node: Support for shell commands & Modules (#70)
- Loading branch information
Showing
12 changed files
with
197 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
|
||
#include "shell.h" | ||
#include <stdio.h> | ||
|
||
static kernel_pid_t DISPATCHER_THREAD_ID; | ||
|
||
static int echo_command(int argc, char **argv) | ||
{ | ||
/* check that the command is called correctly */ | ||
if (argc != 2) { | ||
puts("usage: echo <message>"); | ||
puts("Note: to echo multiple words wrap the message in \"\""); | ||
return 1; | ||
} | ||
|
||
/* print the first argument */ | ||
puts(argv[1]); | ||
|
||
return 0; | ||
} | ||
|
||
/** | ||
* @brief Sends an event to the dispatcher. | ||
* @example send_event 1 | ||
*/ | ||
static int send_event(int argc, char **argv) { | ||
if (argc != 2) { | ||
puts("usage: send_event <event>"); | ||
return 1; | ||
} | ||
|
||
msg_t message; | ||
message.type = atoi(argv[1]); | ||
|
||
msg_try_send(&message, DISPATCHER_THREAD_ID); | ||
|
||
return 0; | ||
} | ||
|
||
const shell_command_t SHELL_COMMANDS[] = { | ||
{ "echo", "Prints the message to the console", echo_command }, | ||
{ "send_event", "Sends an event to the dispatcher. send_event 1", send_event }, | ||
{ NULL, NULL, NULL } | ||
}; | ||
|
||
void shell_loop(void) { | ||
/* buffer to read commands */ | ||
char line_buf[SHELL_DEFAULT_BUFSIZE]; | ||
|
||
cout << "Starting shell loop" << endl; | ||
|
||
/* run the shell, this will block the thread waiting for incoming commands */ | ||
shell_run_forever(SHELL_COMMANDS, line_buf, SHELL_DEFAULT_BUFSIZE); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include $(RIOTBASE)/Makefile.base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
USEMODULE += random | ||
# Set a different prng than the default | ||
USEMODULE += prng_xorshift |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Use an immediate variable to evaluate `MAKEFILE_LIST` now | ||
USEMODULE_INCLUDES_external_module := $(LAST_MAKEFILEDIR)/include | ||
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_external_module) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (C) 2018 Freie Universität Berlin | ||
* | ||
* 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 tests | ||
* @{ | ||
* | ||
* @file | ||
* @brief Test the EXTERNAL_MODULE_DIRS feature | ||
* @note Define a shared variable | ||
* | ||
* @author Gaëtan Harter <gaetan.harter@fu-berlin.de> | ||
* | ||
* @} | ||
*/ | ||
|
||
#include "external_module.h" | ||
#include "auto_init_priorities.h" | ||
#include "auto_init_utils.h" | ||
|
||
#define PRIO AUTO_INIT_PRIORITY_AFTER(AUTO_INIT_PRIO_MOD_RANDOM) | ||
|
||
AUTO_INIT(auto_init_external_module, PRIO); | ||
|
||
bool external_module_initialized = false; | ||
char *external_module_message = "Linking worked"; | ||
|
||
void auto_init_external_module(void) | ||
{ | ||
external_module_initialized = true; | ||
} |
50 changes: 50 additions & 0 deletions
50
node/code/modules/external_module/include/external_module.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (C) 2018 Freie Universität Berlin | ||
* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* @defgroup | ||
* @ingroup | ||
* @brief | ||
* @{ | ||
* | ||
* @file | ||
* @brief | ||
* | ||
* @author Gaëtan Harter <gaetan.harter@fu-berlin.de> | ||
*/ | ||
#ifndef EXTERNAL_MODULE_H | ||
#define EXTERNAL_MODULE_H | ||
|
||
#include <stdbool.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @brief true: this module hase been initialized | ||
* false: this module has not been initialized | ||
*/ | ||
extern bool external_module_initialized; | ||
|
||
/** | ||
* @brief A simple string message | ||
*/ | ||
extern char *external_module_message; | ||
|
||
/** | ||
* @brief Auto-init function of this module to be called on system start up | ||
*/ | ||
void auto_init_external_module(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
/** @} */ | ||
#endif /* EXTERNAL_MODULE_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters