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

Convert examples

This commit is contained in:
René Kijewski 2014-02-24 23:39:23 +01:00
parent 829966ee32
commit 0eb7597ab1
5 changed files with 75 additions and 80 deletions

View File

@ -68,9 +68,10 @@ static void appserver_thread(void)
ccnl_riot_appserver_start(relay_pid);
}
static void riot_ccn_appserver(char *str)
static void riot_ccn_appserver(int argc, char **argv)
{
(void) str; /* unused */
(void) argc; /* the function takes no arguments */
(void) argv;
if (appserver_pid) {
/* already running */
@ -82,17 +83,15 @@ static void riot_ccn_appserver(char *str)
}
#endif
static void riot_ccn_express_interest(char *str)
static void riot_ccn_express_interest(int argc, char **argv)
{
char *given_interest = strtok(str, " "); /* str=interest, skip that */
given_interest = strtok(NULL, " ");
static const char *default_interest = "/ccnx/0.7.1/doc/technical/CanonicalOrder.txt";
if (!given_interest) {
if (argc < 2) {
strncpy(small_buf, default_interest, 100); // null terminated
}
else {
strncpy(small_buf, given_interest, 100);
strncpy(small_buf, argv[1], 100);
}
DEBUG("in='%s'\n", small_buf);
@ -152,49 +151,42 @@ static void relay_thread(void)
ccnl_riot_relay_start(shell_max_cache_entries, shell_threshold_prefix, shell_threshold_aggregate);
}
static void riot_ccn_relay_start(char *str)
static void riot_ccn_relay_start(int argc, char **argv)
{
if (relay_pid) {
/* already running */
return;
}
char *toc_str = strtok(str, " ");
toc_str = strtok(NULL, " ");
if (!toc_str) {
if (argc < 2) {
shell_max_cache_entries = CCNL_DEFAULT_MAX_CACHE_ENTRIES;
}
else {
shell_max_cache_entries = atoi(toc_str);
shell_max_cache_entries = atoi(argv[1]);
}
toc_str = strtok(NULL, " ");
if (!toc_str) {
if (argc < 3) {
shell_threshold_prefix = CCNL_DEFAULT_THRESHOLD_PREFIX;
}
else {
shell_threshold_prefix = atoi(toc_str);
shell_threshold_prefix = atoi(argv[2]);
}
toc_str = strtok(NULL, " ");
if (!toc_str) {
if (argc < 4) {
shell_threshold_aggregate = CCNL_DEFAULT_THRESHOLD_AGGREGATE;
}
else {
shell_threshold_aggregate = atoi(toc_str);
shell_threshold_aggregate = atoi(argv[3]);
}
relay_pid = thread_create(relay_stack, KERNEL_CONF_STACKSIZE_PRINTF, PRIORITY_MAIN - 2, CREATE_STACKTEST, relay_thread, "relay");
DEBUG("ccn-lite relay on thread_id %d...\n", relay_pid);
}
static void riot_ccn_relay_stop(char *str)
static void riot_ccn_relay_stop(int argc, char **argv)
{
(void) str; /* unused */
(void) argc; /* the function takes no arguments */
(void) argv;
msg_t m;
m.content.value = 0;
@ -206,9 +198,10 @@ static void riot_ccn_relay_stop(char *str)
}
#if RIOT_CCN_TESTS
static void riot_ccn_pit_test(char *str)
static void riot_ccn_pit_test(int argc, char **argv)
{
(void) str; /* unused */
(void) argc; /* the function takes no arguments */
(void) argv;
char name[] = "/riot/test";
@ -254,9 +247,10 @@ static void riot_ccn_pit_test(char *str)
printf("done: tried to send %d interests\n", segment);
}
static void riot_ccn_fib_test(char *str)
static void riot_ccn_fib_test(int argc, char **argv)
{
(void) str; /* unused */
(void) argc; /* the function takes no arguments */
(void) argv;
char type[] = "newTRANSface";
char faceid[] = "42";
@ -283,9 +277,10 @@ static void riot_ccn_fib_test(char *str)
}
#endif
static void riot_ccn_populate(char *str)
static void riot_ccn_populate(int argc, char **argv)
{
(void) str; /* unused */
(void) argc; /* the function takes no arguments */
(void) argv;
msg_t m;
m.content.value = 0;
@ -293,9 +288,10 @@ static void riot_ccn_populate(char *str)
msg_send(&m, relay_pid, 1);
}
static void riot_ccn_stat(char *str)
static void riot_ccn_stat(int argc, char **argv)
{
(void) str; /* unused */
(void) argc; /* the function takes no arguments */
(void) argv;
msg_t m;
m.content.value = 0;

View File

@ -13,47 +13,37 @@
/* RPL shell command handlers */
/**
* @brief Shell command to initializes RPL and Destiny
*
* @param[in] str Shell input
*/
void rpl_udp_init(char *str);
void rpl_udp_init(int argc, char **argv);
/**
* @brief Shell command to set node's ID
*
* @param[in] str Shell input
*/
void rpl_udp_set_id(char *id);
void rpl_udp_set_id(int argc, char **argv);
/**
* @brief Loops through the routing table
*
* @param[in] unused Guess what
*/
void rpl_udp_loop(char *unused);
void rpl_udp_loop(int argc, char **argv);
/**
* @brief Shows the routing table
*
* @param[in] unused Guess what
*/
void rpl_udp_table(char *unused);
void rpl_udp_table(int argc, char **argv);
/**
* @brief Shows the dodag
*
* @param[in] unused Guess what
*/
void rpl_udp_dodag(char *unused);
void rpl_udp_dodag(int argc, char **argv);
/* UDP shell command handlers */
void udp_server(char *unused);
void udp_send(char *str);
void udp_server(int argc, char **argv);
void udp_send(int argc, char **argv);
/* helper command handlers */
void rpl_udp_ip(char *unused);
void rpl_udp_ip(int argc, char **argv);
void rpl_udp_ignore(char *addr);
void rpl_udp_ignore(int argc, char **argv);
/* monitoring thread */
void rpl_udp_monitor(void);

View File

@ -40,23 +40,25 @@ extern uint8_t ipv6_ext_hdr_len;
msg_t msg_q[RCV_BUFFER_SIZE];
/* prints current IPv6 adresses */
void rpl_udp_ip(char *unused)
void rpl_udp_ip(int argc, char **argv)
{
(void) unused;
(void) argc;
(void) argv;
ipv6_iface_print_addrs();
}
void rpl_udp_set_id(char *id_str)
void rpl_udp_set_id(int argc, char **argv)
{
int res = sscanf(id_str, "set %hu", &id);
if (res < 1) {
printf("Usage: init address\n");
if (argc != 2) {
printf("Usage: %s address\n", argv[0]);
printf("\taddress must be an 8 bit integer\n");
printf("\n\t(Current address is %u)\n", id);
return;
}
id = atoi(argv[1]);
printf("Set node ID to %u\n", id);
}
@ -119,7 +121,7 @@ void rpl_udp_monitor(void)
transceiver_command_t tcmd;
void rpl_udp_ignore(char *addr)
void rpl_udp_ignore(int argc, char **argv)
{
uint16_t a;
@ -134,13 +136,13 @@ void rpl_udp_ignore(char *addr)
tcmd.transceivers = TRANSCEIVER_CC1100;
tcmd.data = &a;
a = atoi(addr + strlen("ign "));
if (strlen(addr) > strlen("ign ")) {
if (argc == 2) {
a = atoi(argv[1]);
printf("sending to transceiver (%u): %u\n", transceiver_pid, (*(uint8_t *)tcmd.data));
msg_send(&mesg, transceiver_pid, 1);
}
else {
puts("Usage:\tign <addr>");
printf("Usage: %s <addr>\n", argv[0]);
}
}

View File

@ -40,26 +40,22 @@ ipv6_addr_t std_addr;
uint8_t is_root = 0;
void rpl_udp_init(char *str)
void rpl_udp_init(int argc, char **argv)
{
transceiver_command_t tcmd;
msg_t m;
uint8_t chan = RADIO_CHANNEL;
char *toc_str = strtok(str, " ");
toc_str = strtok(NULL, " ");
if (!toc_str) {
printf("Usage: init (r|n)\n");
if (argc != 2) {
printf("Usage: %s (r|n)\n", argv[0]);
printf("\tr\tinitialize as root\n");
printf("\tn\tinitialize as node router\n");
return;
}
char command = *toc_str;
uint8_t state;
char command = argv[1][0];
if ((command == 'n') || (command == 'r')) {
printf("INFO: Initialize as %s on address %d\n", ((command == 'n') ? "node" : "root"), id);
@ -118,9 +114,10 @@ void rpl_udp_init(char *str)
/* start transceiver watchdog */
}
void rpl_udp_loop(char *unused)
void rpl_udp_loop(int argc, char **argv)
{
(void) unused;
(void) argc;
(void) argv;
rpl_routing_entry_t *rtable;
@ -161,9 +158,10 @@ void rpl_udp_loop(char *unused)
printf("########################\n");
}
void rpl_udp_table(char *unused)
void rpl_udp_table(int argc, char **argv)
{
(void) unused;
(void) argc;
(void) argv;
rpl_routing_entry_t *rtable;
rtable = rpl_get_routing_table();
@ -187,9 +185,10 @@ void rpl_udp_table(char *unused)
printf("$\n");
}
void rpl_udp_dodag(char *unused)
void rpl_udp_dodag(int argc, char **argv)
{
(void) unused;
(void) argc;
(void) argv;
printf("---------------------------\n");
rpl_dodag_t *mydodag = rpl_get_my_dodag();

View File

@ -19,6 +19,7 @@
*/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <inttypes.h>
@ -41,9 +42,11 @@ char addr_str[IPV6_MAX_ADDR_STR_LEN];
void init_udp_server(void);
/* UDP server thread */
void udp_server(char *unused)
void udp_server(int argc, char **argv)
{
(void) unused;
(void) argc;
(void) argv;
int udp_server_thread_pid = thread_create(udp_server_stack_buffer, KERNEL_CONF_STACKSIZE_MAIN, PRIORITY_MAIN, CREATE_STACKTEST, init_udp_server, "init_udp_server");
printf("UDP SERVER ON PORT %d (THREAD PID: %d)\n", HTONS(SERVER_PORT), udp_server_thread_pid);
}
@ -83,7 +86,7 @@ void init_udp_server(void)
}
/* UDP send command */
void udp_send(char *str)
void udp_send(int argc, char **argv)
{
int sock;
sockaddr6_t sa;
@ -92,11 +95,16 @@ void udp_send(char *str)
int address;
char text[5];
if (sscanf(str, "send %i %s", &address, text) < 2) {
if (argc != 3) {
printf("usage: send <addr> <text>\n");
return;
}
address = atoi(argv[1]);
strncpy(text, argv[2], sizeof (text));
text[sizeof (text) - 1] = 0;
sock = destiny_socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
if (-1 == sock) {