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

shell: Return-based error-handling for shell handlers

- Included the missing parts.
- Squashed with @authmillenon's commit
This commit is contained in:
kushalsingh007 2015-03-20 13:21:45 +05:30
parent ad69413d22
commit 9aae656be9
33 changed files with 488 additions and 289 deletions

View File

@ -60,14 +60,14 @@ unsigned char big_buf[3 * 1024];
char small_buf[PAYLOAD_SIZE];
#if RIOT_CCN_APPSERVER
static void riot_ccn_appserver(int argc, char **argv)
static int riot_ccn_appserver(int argc, char **argv)
{
(void) argc; /* the function takes no arguments */
(void) argv;
if (_appserver_pid != KERNEL_PID_UNDEF) {
/* already running */
return;
return 1;
}
_appserver_pid = thread_create(
@ -75,10 +75,12 @@ static void riot_ccn_appserver(int argc, char **argv)
PRIORITY_MAIN - 1, CREATE_STACKTEST,
ccnl_riot_appserver_start, (void *) &_relay_pid, "appserver");
DEBUG("ccn-lite appserver on thread_id %" PRIkernel_pid "...\n", _appserver_pid);
return 0;
}
#endif
static void riot_ccn_express_interest(int argc, char **argv)
static int riot_ccn_express_interest(int argc, char **argv)
{
if (argc < 2) {
strncpy(small_buf, DEFAULT_INTEREST, sizeof(small_buf));
@ -93,7 +95,7 @@ static void riot_ccn_express_interest(int argc, char **argv)
if (content_len == 0) {
puts("riot_get returned 0 bytes...aborting!");
return;
return 1;
}
puts("####################################################");
@ -101,13 +103,15 @@ static void riot_ccn_express_interest(int argc, char **argv)
printf("data='%s'\n", big_buf);
puts("####################################################");
puts("done");
return 0;
}
static void riot_ccn_register_prefix(int argc, char **argv)
static int riot_ccn_register_prefix(int argc, char **argv)
{
if (argc < 4) {
puts("enter: prefix </path/to/abc> <type> <faceid>");
return;
return 1;
}
strncpy(small_buf, argv[1], 100);
@ -121,18 +125,20 @@ static void riot_ccn_register_prefix(int argc, char **argv)
DEBUG("shell received: '%s'\n", big_buf);
DEBUG("received %d bytes.\n", content_len);
puts("done");
return 0;
}
static void riot_ccn_relay_config(int argc, char **argv)
static int riot_ccn_relay_config(int argc, char **argv)
{
if (_relay_pid == KERNEL_PID_UNDEF) {
puts("ccnl stack not running");
return;
return 1;
}
if (argc < 2) {
printf("%s: <max_cache_entries>\n", argv[0]);
return;
return 1;
}
msg_t m;
@ -170,12 +176,12 @@ static void riot_ccn_transceiver_start(kernel_pid_t _relay_pid)
}
}
static void riot_ccn_relay_start(void)
static int riot_ccn_relay_start(void)
{
if (_relay_pid != KERNEL_PID_UNDEF) {
DEBUG("ccn-lite relay on thread_id %d...please stop it first!\n", _relay_pid);
/* already running */
return;
return 1;
}
_relay_pid = thread_create(
@ -185,9 +191,11 @@ static void riot_ccn_relay_start(void)
DEBUG("ccn-lite relay on thread_id %" PRIkernel_pid "...\n", _relay_pid);
riot_ccn_transceiver_start(_relay_pid);
return 0;
}
static void riot_ccn_relay_stop(int argc, char **argv)
static int riot_ccn_relay_stop(int argc, char **argv)
{
(void) argc; /* the function takes no arguments */
(void) argv;
@ -199,10 +207,12 @@ static void riot_ccn_relay_stop(int argc, char **argv)
/* mark relay as not running */
_relay_pid = 0;
return 0;
}
#if RIOT_CCN_TESTS
static void riot_ccn_pit_test(int argc, char **argv)
static int riot_ccn_pit_test(int argc, char **argv)
{
(void) argc; /* the function takes no arguments */
(void) argv;
@ -249,9 +259,11 @@ static void riot_ccn_pit_test(int argc, char **argv)
}
printf("done: tried to send %d interests\n", segment);
return 0;
}
static void riot_ccn_fib_test(int argc, char **argv)
static int riot_ccn_fib_test(int argc, char **argv)
{
(void) argc; /* the function takes no arguments */
(void) argv;
@ -278,10 +290,12 @@ static void riot_ccn_fib_test(int argc, char **argv)
DEBUG("%d: '%s'\n", i, big_buf);
printf("done: %d\n", i - 1);
return 0;
}
#endif
static void riot_ccn_populate(int argc, char **argv)
static int riot_ccn_populate(int argc, char **argv)
{
(void) argc; /* the function takes no arguments */
(void) argv;
@ -290,9 +304,11 @@ static void riot_ccn_populate(int argc, char **argv)
m.content.value = 0;
m.type = CCNL_RIOT_POPULATE;
msg_send(&m, _relay_pid);
return 0;
}
static void riot_ccn_stat(int argc, char **argv)
static int riot_ccn_stat(int argc, char **argv)
{
(void) argc; /* the function takes no arguments */
(void) argv;
@ -301,6 +317,8 @@ static void riot_ccn_stat(int argc, char **argv)
m.content.value = 0;
m.type = CCNL_RIOT_PRINT_STAT;
msg_send(&m, _relay_pid);
return 0;
}
static const shell_command_t sc[] = {

View File

@ -39,7 +39,7 @@ extern uint8_t ipv6_ext_hdr_len;
static msg_t msg_q[RCV_BUFFER_SIZE];
void rpl_udp_set_id(int argc, char **argv)
int rpl_udp_set_id(int argc, char **argv)
{
if (argc != 2) {
printf("Usage: %s address\n", argv[0]);
@ -49,12 +49,14 @@ void rpl_udp_set_id(int argc, char **argv)
printf("\taddress must be an 16 bit integer\n");
#endif
printf("\n\t(Current address is %u)\n", id);
return;
return 1;
}
id = atoi(argv[1]);
printf("Set node ID to %u\n", id);
return 0;
}
void *rpl_udp_monitor(void *arg)
@ -123,18 +125,18 @@ void *rpl_udp_monitor(void *arg)
static transceiver_command_t tcmd;
void rpl_udp_ignore(int argc, char **argv)
int rpl_udp_ignore(int argc, char **argv)
{
uint16_t a;
if (argc < 2) {
printf("Usage: %s <addr>\n", argv[0]);
return;
return 1;
}
if (transceiver_pid == KERNEL_PID_UNDEF) {
puts("Transceiver not runnning.");
return;
return 1;
}
/* cppcheck: a is actually read via tcmd.data */
@ -151,4 +153,6 @@ void rpl_udp_ignore(int argc, char **argv)
printf("sending to transceiver (%" PRIkernel_pid "): %u\n", transceiver_pid,
(*(uint8_t *)tcmd.data));
msg_send(&mesg, transceiver_pid);
return 0;
}

View File

@ -44,7 +44,7 @@ radio_address_t id;
static uint8_t is_root = 0;
void rpl_udp_init(int argc, char **argv)
int rpl_udp_init(int argc, char **argv)
{
transceiver_command_t tcmd;
msg_t m;
@ -55,7 +55,7 @@ void rpl_udp_init(int argc, char **argv)
printf("\tr\tinitialize as root\n");
printf("\tn\tinitialize as node router\n");
printf("\th\tinitialize as non-routing node (host-mode)\n");
return;
return 1;
}
char command = argv[1][0];
@ -67,7 +67,7 @@ void rpl_udp_init(int argc, char **argv)
#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY) || defined(MODULE_CC110X_LEGACY_CSMA))
if (!id || (id > 255)) {
printf("ERROR: address not a valid 8 bit integer\n");
return;
return 1;
}
#endif
@ -91,7 +91,7 @@ void rpl_udp_init(int argc, char **argv)
msg_send_receive(&m, &m, transceiver_pid);
if( chan == UNASSIGNED_CHANNEL ) {
puts("ERROR: channel NOT set! Aborting initialization.");
return;
return 1;
}
printf("Channel set to %" PRIi32 "\n", chan);
@ -156,7 +156,7 @@ void rpl_udp_init(int argc, char **argv)
}
else {
printf("ERROR: Unknown command '%c'\n", command);
return;
return 1;
}
if (command != 'h') {
@ -165,9 +165,11 @@ void rpl_udp_init(int argc, char **argv)
puts("Transport layer initialized");
/* start transceiver watchdog */
return 0;
}
void rpl_udp_dodag(int argc, char **argv)
int rpl_udp_dodag(int argc, char **argv)
{
(void) argc;
(void) argv;
@ -178,7 +180,7 @@ void rpl_udp_dodag(int argc, char **argv)
if (mydodag == NULL) {
printf("Not part of a dodag\n");
printf("---------------------------\n");
return;
return 1;
}
printf("Part of Dodag:\n");
@ -193,4 +195,6 @@ void rpl_udp_dodag(int argc, char **argv)
}
printf("---------------------------\n");
return 0;
}

View File

@ -31,7 +31,7 @@ extern "C" {
* @param[in] argc Argument count
* @param[in] argv Arguments
*/
void rpl_udp_init(int argc, char **argv);
int rpl_udp_init(int argc, char **argv);
/**
* @brief Shell command to set node's ID
@ -42,7 +42,7 @@ void rpl_udp_init(int argc, char **argv);
* @param[in] argc Argument count
* @param[in] argv Arguments
*/
void rpl_udp_set_id(int argc, char **argv);
int rpl_udp_set_id(int argc, char **argv);
/**
* @brief Shows the dodag
@ -52,7 +52,7 @@ void rpl_udp_set_id(int argc, char **argv);
* @param[in] argc Argument count
* @param[in] argv Arguments
*/
void rpl_udp_dodag(int argc, char **argv);
int rpl_udp_dodag(int argc, char **argv);
/**
* @brief Command handler to start a UDP server
@ -62,7 +62,7 @@ void rpl_udp_dodag(int argc, char **argv);
* @param[in] argc Argument count
* @param[in] argv Arguments
*/
void udp_server(int argc, char **argv);
int udp_server(int argc, char **argv);
/**
* @brief Sends a UDP datagram
@ -74,7 +74,7 @@ void udp_server(int argc, char **argv);
* @param[in] argc Argument count
* @param[in] argv Arguments
*/
void udp_send(int argc, char **argv);
int udp_send(int argc, char **argv);
/**
* @brief Ignore a certain node
@ -86,7 +86,7 @@ void udp_send(int argc, char **argv);
* @param[in] argc Argument count
* @param[in] argv Arguments
*/
void rpl_udp_ignore(int argc, char **argv);
int rpl_udp_ignore(int argc, char **argv);
/**
* @brief monitoring thread start function

View File

@ -41,7 +41,7 @@ char addr_str[IPV6_MAX_ADDR_STR_LEN];
static void *init_udp_server(void *);
/* UDP server thread */
void udp_server(int argc, char **argv)
int udp_server(int argc, char **argv)
{
(void) argc;
(void) argv;
@ -53,6 +53,8 @@ void udp_server(int argc, char **argv)
NULL,
"init_udp_server");
printf("UDP SERVER ON PORT %d (THREAD PID: %" PRIkernel_pid ")\n", HTONS(SERVER_PORT), udp_server_thread_pid);
return 0;
}
static void *init_udp_server(void *arg)
@ -93,9 +95,9 @@ static void *init_udp_server(void *arg)
}
/* UDP send command */
void udp_send(int argc, char **argv)
int udp_send(int argc, char **argv)
{
int sock;
int sock, res;
sockaddr6_t sa;
ipv6_addr_t ipaddr;
int bytes_sent;
@ -104,7 +106,7 @@ void udp_send(int argc, char **argv)
if (argc != 3) {
printf("usage: send <addr> <text>\n");
return;
return 1;
}
address = atoi(argv[1]);
@ -116,7 +118,7 @@ void udp_send(int argc, char **argv)
if (-1 == sock) {
printf("Error Creating Socket!");
return;
return 1;
}
memset(&sa, 0, sizeof(sa));
@ -138,12 +140,16 @@ void udp_send(int argc, char **argv)
if (bytes_sent < 0) {
printf("Error sending packet!\n");
res = 1;
}
else {
printf("Successful deliverd %i bytes over UDP to %s to 6LoWPAN\n",
bytes_sent, ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN,
&ipaddr));
res = 0;
}
socket_base_close(sock);
return res;
}

View File

@ -27,7 +27,7 @@ extern "C" {
#endif
void thread_print_all(void);
void _ps_handler(int argc, char **argv);
int _ps_handler(int argc, char **argv);
#ifdef __cplusplus
}

View File

@ -41,8 +41,11 @@ extern "C" {
* This functionality can be used by getopt() or a similar function.
* @param[in] argc Number of arguments supplied to the function invocation.
* @param[in] argv The supplied argument list.
*
* @return 0 on success
* @return Anything else on failure
*/
typedef void (*shell_command_handler_t)(int argc, char **argv);
typedef int (*shell_command_handler_t)(int argc, char **argv);
/**
* @brief A single command in the list of the supported commands.

View File

@ -26,7 +26,7 @@
#include "cc110x_legacy_csma.h"
void _cc110x_get_set_address_handler(int argc, char **argv)
int _cc110x_get_set_address_handler(int argc, char **argv)
{
if (argc > 1) {
int16_t a = atoi(argv[1]);
@ -36,17 +36,23 @@ void _cc110x_get_set_address_handler(int argc, char **argv)
if (cc1100_get_address() == (radio_address_t)a) {
puts("[OK]");
return 0;
}
else {
puts("Error!");
return 1;
}
}
else {
printf("[cc1100] Got address: %i\n", cc1100_get_address());
return 0;
}
}
void _cc110x_get_set_channel_handler(int argc, char **argv)
int _cc110x_get_set_channel_handler(int argc, char **argv)
{
if (argc > 1) {
int16_t a = atoi(argv[1]);
@ -56,12 +62,18 @@ void _cc110x_get_set_channel_handler(int argc, char **argv)
if (cc1100_get_channel() == a) {
puts("OK");
return 0;
}
else {
puts("Error!");
return 1;
}
}
else {
printf("[cc1100] Got address: %i\n", cc1100_get_channel());
return 0;
}
}

View File

@ -45,7 +45,7 @@ static inline uint8_t sector_read(unsigned char *read_buf, unsigned long sector,
return 0;
}
void _get_sectorsize(int argc, char **argv)
int _get_sectorsize(int argc, char **argv)
{
(void) argc;
(void) argv;
@ -53,13 +53,17 @@ void _get_sectorsize(int argc, char **argv)
unsigned short ssize;
if (MCI_ioctl(GET_SECTOR_SIZE, &ssize) == RES_OK) {
printf("[disk] sector size is %u\n", ssize);
return 0;
}
else {
puts("[disk] Failed to fetch sector size. Card inserted?");
return 1;
}
}
void _get_blocksize(int argc, char **argv)
int _get_blocksize(int argc, char **argv)
{
(void) argc;
(void) argv;
@ -67,13 +71,17 @@ void _get_blocksize(int argc, char **argv)
unsigned long bsize;
if (MCI_ioctl(GET_BLOCK_SIZE, &bsize) == RES_OK) {
printf("[disk] block size is %lu\n", bsize);
return 0;
}
else {
puts("[disk] Failed to fetch block size. Card inserted?");
return 1;
}
}
void _get_sectorcount(int argc, char **argv)
int _get_sectorcount(int argc, char **argv)
{
(void) argc;
(void) argv;
@ -81,13 +89,17 @@ void _get_sectorcount(int argc, char **argv)
unsigned long scount;
if (MCI_ioctl(GET_SECTOR_COUNT, &scount) == RES_OK) {
printf("[disk] sector count is %lu\n", scount);
return 0;
}
else {
puts("[disk] Failed to fetch sector count. Card inserted?");
return 1;
}
}
void _read_sector(int argc, char **argv)
int _read_sector(int argc, char **argv)
{
if (argc == 2) {
unsigned long scount;
@ -99,26 +111,27 @@ void _read_sector(int argc, char **argv)
unsigned char read_buf[ssize];
if (sector_read(read_buf, sectornr, ssize, 0)) {
return;
return 0;
}
}
printf("[disk] Error while reading sector %lu\n", sectornr);
return 1;
}
else {
printf("[disk] Usage:\n%s <SECTOR>\n", argv[0]);
return;
return 1;
}
}
void _read_bytes(int argc, char **argv)
int _read_bytes(int argc, char **argv)
{
unsigned long sector = 1, scount, offset;
unsigned short ssize, length;
if (argc != 3) {
printf("[disk] Usage:\n%s <OFFSET> <LENGTH>\n", argv[0]);
return;
return 1;
}
offset = atol(argv[1]);
@ -146,17 +159,17 @@ void _read_bytes(int argc, char **argv)
tmp = (length >= ssize) ? ssize : length;
}
return;
return 0;
} /* length > (ssize - offset) */
/* read only one sector */
else {
if (sector_read(read_buf, sector, length, offset)) {
return;
return 0;
}
} /* length < (ssize - offset) */
} /* ioctl */
printf("[disk] Error while reading sector %lu\n", sector);
return;
return 1;
}

View File

@ -20,10 +20,12 @@
extern void heap_stats(void);
void _heap_handler(int argc, char **argv)
int _heap_handler(int argc, char **argv)
{
(void) argc;
(void) argv;
heap_stats();
return 0;
}

View File

@ -23,7 +23,7 @@
#include <stdlib.h>
#include "config.h"
void _id_handler(int argc, char **argv)
int _id_handler(int argc, char **argv)
{
if (argc < 2) {
printf("Current id: %u\n", sysconfig.id);
@ -35,6 +35,9 @@ void _id_handler(int argc, char **argv)
if (!config_save()) {
puts("ERROR setting new id");
return 1;
}
}
return 0;
}

View File

@ -30,7 +30,7 @@
static isl29020_t isl29020_dev;
void _get_isl29020_init_handler(int argc, char **argv)
int _get_isl29020_init_handler(int argc, char **argv)
{
(void)argc;
(void)argv;
@ -41,13 +41,15 @@ void _get_isl29020_init_handler(int argc, char **argv)
if (res) {
puts("Error initializing ISL29020 sensor.");
return 1;
}
else {
puts("Initialized ISL29020 sensor with default values");
return 0;
}
}
void _get_isl29020_read_handler(int argc, char **argv)
int _get_isl29020_read_handler(int argc, char **argv)
{
(void)argc;
(void)argv;
@ -56,16 +58,17 @@ void _get_isl29020_read_handler(int argc, char **argv)
if (!isl29020_dev.address) {
puts("Error: please call `isl29020_init` first!");
return;
return 1;
}
val = isl29020_read(&isl29020_dev);
if (val < 0) {
puts("Error reading brightness value from ISL29020.");
return;
return 1;
}
else {
printf("ISL29020: brightness %i LUX\n", val);
return 0;
}
}

View File

@ -27,7 +27,7 @@
#include "timex.h"
#include "vtimer.h"
void _l2_ping_req_handler(int argc, char **argv)
int _l2_ping_req_handler(int argc, char **argv)
{
size_t payload_strlen;
uint16_t count = 5;
@ -35,11 +35,11 @@ void _l2_ping_req_handler(int argc, char **argv)
if (transceiver_pid == KERNEL_PID_UNDEF) {
puts("Transceiver not initialized");
return;
return 1;
}
if (argc < 2) {
printf("Usage:\t%s <ADDR> [COUNT] [MSG]\n", argv[0]);
return;
return 1;
}
char l2_payload[L2_PING_PAYLOAD_SIZE];
@ -82,9 +82,11 @@ void _l2_ping_req_handler(int argc, char **argv)
l2_ping_stats.min_rtt.seconds, l2_ping_stats.min_rtt.microseconds,
l2_ping_stats.avg_rtt.seconds, l2_ping_stats.avg_rtt.microseconds,
l2_ping_stats.max_rtt.seconds, l2_ping_stats.max_rtt.microseconds);
return 0;
}
void _l2_ping_probe_handler(int argc, char **argv)
int _l2_ping_probe_handler(int argc, char **argv)
{
size_t payload_strlen;
uint16_t count = 5;
@ -92,11 +94,11 @@ void _l2_ping_probe_handler(int argc, char **argv)
if (transceiver_pid == KERNEL_PID_UNDEF) {
puts("Transceiver not initialized");
return;
return 1;
}
if (argc < 2) {
printf("Usage:\t%s <ADDR> [COUNT] [MSG]\n", argv[0]);
return;
return 1;
}
char l2_payload[L2_PING_PAYLOAD_SIZE];
@ -128,9 +130,11 @@ void _l2_ping_probe_handler(int argc, char **argv)
printf(" --- ping statistics for host %" PRIu16 " ---\n", l2_ping_stats.dst);
printf(" %" PRIu16 " packets transmitted in %" PRIu32 ".%06" PRIu32 "s\n", l2_ping_stats.ping_count,
period.seconds, period.microseconds);
return 0;
}
void _l2_ping_get_probe_handler(int argc, char **argv)
int _l2_ping_get_probe_handler(int argc, char **argv)
{
(void) argc;
(void) argv;
@ -144,4 +148,6 @@ void _l2_ping_get_probe_handler(int argc, char **argv)
for (uint16_t i = 0; i < count; i++) {
printf("...received %" PRIu16 " probes from node %" PRIu16 ".\n", stats[i].count, stats[i].src);
}
return 0;
}

View File

@ -30,7 +30,7 @@
static l3g4200d_t l3g4200d_dev;
void _get_l3g4200d_init_handler(int argc, char **argv)
int _get_l3g4200d_init_handler(int argc, char **argv)
{
(void)argc;
(void)argv;
@ -42,13 +42,15 @@ void _get_l3g4200d_init_handler(int argc, char **argv)
if (res) {
puts("Error initializing L3G4200D sensor.");
return 1;
}
else {
puts("Initialized L3G4200D sensor with default values");
return 0;
}
}
void _get_l3g4200d_read_handler(int argc, char **argv)
int _get_l3g4200d_read_handler(int argc, char **argv)
{
(void)argc;
(void)argv;
@ -57,17 +59,18 @@ void _get_l3g4200d_read_handler(int argc, char **argv)
if (!l3g4200d_dev.addr) {
puts("Error: please call `l3g4200d_init` first!");
return;
return 1;
}
res = l3g4200d_read(&l3g4200d_dev, &data);
if (res < 0) {
puts("Error reading gyro values from L3G4200D.");
return;
return 1;
}
else {
printf("L3G4200D: gyro values: roll(x): %6i pitch(y): %6i yaw(z): %6i\n",
data.acc_x, data.acc_y, data.acc_z);
return 0;
}
}

View File

@ -29,7 +29,7 @@
static lps331ap_t lps331ap_dev;
void _get_lps331ap_init_handler(int argc, char **argv)
int _get_lps331ap_init_handler(int argc, char **argv)
{
(void)argc;
(void)argv;
@ -39,13 +39,15 @@ void _get_lps331ap_init_handler(int argc, char **argv)
if (res) {
puts("Error initializing LPS331AP sensor.");
return 1;
}
else {
puts("Initialized LPS331AP sensor with default values");
return 0;
}
}
void _get_lps331ap_read_handler(int argc, char **argv)
int _get_lps331ap_read_handler(int argc, char **argv)
{
(void)argc;
(void)argv;
@ -54,7 +56,7 @@ void _get_lps331ap_read_handler(int argc, char **argv)
if (!lps331ap_dev.address) {
puts("Error: please call `lps331ap_init` first!");
return;
return 1;
}
temp = lps331ap_read_temp(&lps331ap_dev);
@ -62,7 +64,7 @@ void _get_lps331ap_read_handler(int argc, char **argv)
if (temp < 0) {
puts("Error reading temperature value from LPS331AP.");
return;
return 1;
}
else {
int temp_abs = temp / 1000;
@ -72,11 +74,13 @@ void _get_lps331ap_read_handler(int argc, char **argv)
if (pres < 0) {
puts("Error reading pressure value from LPS331AP.");
return;
return 1;
}
else {
printf("LPS331AP: pressure: %i mBar\n", pres);
}
return 0;
}
#endif /* MODULE_LPS331AP */

View File

@ -31,7 +31,7 @@
static lsm303dlhc_t lsm303_dev;
void _get_lsm303dlhc_init_handler(int argc, char **argv)
int _get_lsm303dlhc_init_handler(int argc, char **argv)
{
(void)argc;
(void)argv;
@ -45,13 +45,15 @@ void _get_lsm303dlhc_init_handler(int argc, char **argv)
if (error) {
puts("Error initializing lsm303dlhc sensor.");
return 1;
}
else {
puts("Initialized lsm303dlhc sensor with default values");
return 0;
}
}
void _get_lsm303dlhc_read_handler(int argc, char **argv)
int _get_lsm303dlhc_read_handler(int argc, char **argv)
{
(void)argc;
(void)argv;
@ -61,13 +63,13 @@ void _get_lsm303dlhc_read_handler(int argc, char **argv)
if (!lsm303_dev.acc_address || !lsm303_dev.mag_address) {
puts("Error: please call `lsm303dlhc_init` first!");
return;
return 1;
}
error = lsm303dlhc_read_acc(&lsm303_dev, &data);
if (error) {
puts("Error reading accelerometer data from lsm303dlhc.");
return;
return 1;
}
else {
printf("lsm303dlhc: Accelerometer {%i, %i, %i} mg\n", data.x_axis, data.y_axis, data.z_axis);
@ -76,7 +78,7 @@ void _get_lsm303dlhc_read_handler(int argc, char **argv)
error = lsm303dlhc_read_mag(&lsm303_dev, &data);
if (error) {
puts("Error reading magnetometer data from lsm303dlhc.");
return;
return 1;
}
else {
printf("lsm303dlhc: Magnetometer {%i, %i, %i}/1100 gauss\n", data.x_axis, data.y_axis, data.z_axis);
@ -85,10 +87,11 @@ void _get_lsm303dlhc_read_handler(int argc, char **argv)
error = lsm303dlhc_read_temp(&lsm303_dev, &(data.x_axis));
if (error) {
puts("Error reading temperature data from lsm303dlhc.");
return;
return 1;
}
else {
printf("lsm303dlhc: Temperature %i\n", data.x_axis);
return 0;
}
}

View File

@ -21,19 +21,23 @@
#include <stdio.h>
#include "ltc4150.h"
void _get_current_handler(int argc, char **argv)
int _get_current_handler(int argc, char **argv)
{
(void) argc;
(void) argv;
printf("Power usage: %.4f mA (%.4f mA avg/ %.4f mAh total / %i usec)\n",
ltc4150_get_current_mA(), ltc4150_get_avg_mA(), ltc4150_get_total_mAh(), ltc4150_get_interval());
return 0;
}
void _reset_current_handler(int argc, char **argv)
int _reset_current_handler(int argc, char **argv)
{
(void) argc;
(void) argv;
ltc4150_start();
return 0;
}

View File

@ -26,7 +26,7 @@
#include "hwtimer.h"
#include "random.h"
void _mersenne_init(int argc, char **argv)
int _mersenne_init(int argc, char **argv)
{
int initval;
@ -40,12 +40,16 @@ void _mersenne_init(int argc, char **argv)
}
genrand_init(initval);
return 0;
}
void _mersenne_get(int argc, char **argv)
int _mersenne_get(int argc, char **argv)
{
(void) argc;
(void) argv;
printf("%" PRIu32 "\n", genrand_uint32());
return 0;
}

View File

@ -40,19 +40,19 @@ static uint8_t addrs[ADDR_REGISTERED_MAX][ADDRS_LEN_MAX];
#include "ipv6.h"
#endif
void _net_if_ifconfig_add(int if_id, int argc, char **argv);
void _net_if_ifconfig_add_ipv6(int if_id, int argc, char **argv);
void _net_if_ifconfig_set(int if_id, char *key, char *value);
void _net_if_ifconfig_set_srcaddrmode(int if_id, char *mode);
void _net_if_ifconfig_set_eui64(int if_id, char *addr);
void _net_if_ifconfig_set_hwaddr(int if_id, char *addr);
void _net_if_ifconfig_set_pan_id(int if_id, char *pan_id);
void _net_if_ifconfig_set_channel(int if_id, char *channel);
void _net_if_ifconfig_create(char *transceivers_str);
int _net_if_ifconfig_add(int if_id, int argc, char **argv);
int _net_if_ifconfig_add_ipv6(int if_id, int argc, char **argv);
int _net_if_ifconfig_set(int if_id, char *key, char *value);
int _net_if_ifconfig_set_srcaddrmode(int if_id, char *mode);
int _net_if_ifconfig_set_eui64(int if_id, char *addr);
int _net_if_ifconfig_set_hwaddr(int if_id, char *addr);
int _net_if_ifconfig_set_pan_id(int if_id, char *pan_id);
int _net_if_ifconfig_set_channel(int if_id, char *channel);
int _net_if_ifconfig_create(char *transceivers_str);
int _net_if_ifconfig_ipv6_addr_convert(net_if_addr_t *addr, void *addr_data,
char *type, char *addr_data_str,
char *addr_data_len);
void _net_if_ifconfig_list(int if_id);
int _net_if_ifconfig_list(int if_id);
int is_number(char *str)
{
@ -142,7 +142,7 @@ void create_usage(void)
);
}
void _net_if_ifconfig(int argc, char **argv)
int _net_if_ifconfig(int argc, char **argv)
{
if (argc < 2) {
int if_id = -1;
@ -151,173 +151,173 @@ void _net_if_ifconfig(int argc, char **argv)
_net_if_ifconfig_list(if_id);
}
return;
return 0;
}
else if (strcmp(argv[1], "create") == 0) {
_net_if_ifconfig_create(argv[2]);
return;
return _net_if_ifconfig_create(argv[2]);
}
else if (is_number(argv[1])) {
int if_id = atoi(argv[1]);
if (argc < 3) {
_net_if_ifconfig_list(if_id);
return;
return _net_if_ifconfig_list(if_id);
}
else if (strcmp(argv[2], "add") == 0) {
if (argc < 5) {
add_usage();
return;
return 1;
}
_net_if_ifconfig_add(if_id, argc, argv);
return;
return _net_if_ifconfig_add(if_id, argc, argv);
}
else if (strcmp(argv[2], "set") == 0) {
if (argc < 5) {
set_usage();
return;
return 1;
}
_net_if_ifconfig_set(if_id, argv[3], argv[4]);
return;
return _net_if_ifconfig_set(if_id, argv[3], argv[4]);
}
}
create_usage();
printf("or: ifconfig [<if_id> [add <protocol> <addr>|set <key> <value>]]\n");
return 1;
}
void _net_if_ifconfig_set_srcaddrmode(int if_id, char *mode)
int _net_if_ifconfig_set_srcaddrmode(int if_id, char *mode)
{
if (mode == NULL) {
set_usage();
return;
return 1;
}
else if (strcmp(mode, "short") == 0) {
net_if_set_src_address_mode(if_id, NET_IF_TRANS_ADDR_M_SHORT);
return !net_if_set_src_address_mode(if_id, NET_IF_TRANS_ADDR_M_SHORT);
}
else if (strcmp(mode, "long") == 0) {
net_if_set_src_address_mode(if_id, NET_IF_TRANS_ADDR_M_LONG);
return !net_if_set_src_address_mode(if_id, NET_IF_TRANS_ADDR_M_LONG);
}
else {
set_usage();
return;
return 1;
}
}
void _net_if_ifconfig_set_eui64(int if_id, char *eui64_str)
int _net_if_ifconfig_set_eui64(int if_id, char *eui64_str)
{
net_if_eui64_t eui64;
if (eui64_str == NULL) {
set_usage();
return;
return 1;
}
net_if_hex_to_eui64(&eui64, eui64_str);
net_if_set_eui64(if_id, &eui64);
return 0;
}
void _net_if_ifconfig_set_hwaddr(int if_id, char *addr_str)
int _net_if_ifconfig_set_hwaddr(int if_id, char *addr_str)
{
int addr;
if (addr_str == NULL) {
set_usage();
return;
return 1;
}
if (is_number(addr_str)) {
if ((addr = atoi(addr_str)) > 0xffff) {
set_usage();
return;
return 1;
}
}
else {
if ((addr = strtoul(addr_str, NULL, 16)) > 0xffff) {
set_usage();
return;
return 1;
}
}
net_if_set_hardware_address(if_id, (uint16_t)addr);
return net_if_set_hardware_address(if_id, (uint16_t)addr) == 0;
}
void _net_if_ifconfig_set_pan_id(int if_id, char *pan_str)
int _net_if_ifconfig_set_pan_id(int if_id, char *pan_str)
{
int pan_id;
if (pan_str == NULL) {
set_usage();
return;
return 1;
}
if (is_number(pan_str)) {
if ((pan_id = atoi(pan_str)) > 0xffff) {
set_usage();
return;
return 1;
}
}
else {
if ((pan_id = strtoul(pan_str, NULL, 16)) > 0xffff) {
set_usage();
return;
return 1;
}
}
net_if_set_pan_id(if_id, (uint16_t) pan_id);
return net_if_set_pan_id(if_id, (uint16_t) pan_id) == -1;
}
void _net_if_ifconfig_set_channel(int if_id, char *chan_str)
int _net_if_ifconfig_set_channel(int if_id, char *chan_str)
{
int channel;
if (chan_str == NULL) {
set_usage();
return;
return 1;
}
if (is_number(chan_str)) {
if ((channel = atoi(chan_str)) > 0xffff) {
set_usage();
return;
return 1;
}
}
else {
if ((channel = strtoul(chan_str, NULL, 16)) > 0xffff) {
set_usage();
return;
return 1;
}
}
net_if_set_channel(if_id, (uint16_t) channel);
return net_if_set_channel(if_id, (uint16_t) channel) == -1;
}
void _net_if_ifconfig_set(int if_id, char *key, char *value)
int _net_if_ifconfig_set(int if_id, char *key, char *value)
{
if (strcmp(key, "sam") == 0 || strcmp(key, "srcaddrmode") == 0) {
_net_if_ifconfig_set_srcaddrmode(if_id, value);
return _net_if_ifconfig_set_srcaddrmode(if_id, value);
}
else if (strcmp(key, "eui64") == 0) {
_net_if_ifconfig_set_eui64(if_id, value);
return _net_if_ifconfig_set_eui64(if_id, value);
}
else if (strcmp(key, "hwaddr") == 0) {
_net_if_ifconfig_set_hwaddr(if_id, value);
return _net_if_ifconfig_set_hwaddr(if_id, value);
}
else if (strcmp(key, "pan") == 0 || strcmp(key, "pan_id") == 0) {
_net_if_ifconfig_set_pan_id(if_id, value);
return _net_if_ifconfig_set_pan_id(if_id, value);
}
else if (strcmp(key, "chan") == 0 || strcmp(key, "channel") == 0) {
_net_if_ifconfig_set_channel(if_id, value);
return _net_if_ifconfig_set_channel(if_id, value);
}
else {
set_usage();
return;
return 1;
}
}
void _net_if_ifconfig_add_ipv6(int if_id, int argc, char **argv)
int _net_if_ifconfig_add_ipv6(int if_id, int argc, char **argv)
{
char *type;
char *addr_str;
@ -332,7 +332,7 @@ void _net_if_ifconfig_add_ipv6(int if_id, int argc, char **argv)
}
else {
add_usage();
return;
return 1;
}
}
else {
@ -353,7 +353,7 @@ void _net_if_ifconfig_add_ipv6(int if_id, int argc, char **argv)
if (!_net_if_ifconfig_ipv6_addr_convert(&addr, addr_data, type,
addr_data_str, addr_data_len)) {
add_usage();
return;
return 1;
}
#ifdef MODULE_SIXLOWPAN
@ -364,7 +364,7 @@ void _net_if_ifconfig_add_ipv6(int if_id, int argc, char **argv)
NDP_OPT_PI_PLIFETIME_INFINITE, 1,
ICMPV6_NDP_OPT_PI_FLAG_AUTONOM) != SIXLOWERROR_SUCCESS) {
add_usage();
return;
return 1;
}
}
else if (addr.addr_protocol & NET_IF_L3P_IPV6_ADDR) {
@ -377,36 +377,39 @@ void _net_if_ifconfig_add_ipv6(int if_id, int argc, char **argv)
if (!ipv6_net_if_add_addr(if_id, &ipv6_addr, NDP_ADDR_STATE_PREFERRED,
0, 0, is_anycast)) {
add_usage();
return;
return 1;
}
}
else {
add_usage();
return;
return 1;
}
#else
if (net_if_add_address(if_id, &addr) < 0) {
add_usage();
return;
return 1;
}
addr_registered++;
#endif
return 0;
}
void _net_if_ifconfig_add(int if_id, int argc, char **argv)
int _net_if_ifconfig_add(int if_id, int argc, char **argv)
{
if (strcmp(argv[3], "ipv6") == 0) {
_net_if_ifconfig_add_ipv6(if_id, argc, argv);
return _net_if_ifconfig_add_ipv6(if_id, argc, argv);
}
else {
add_usage();
return 1;
}
}
void _net_if_ifconfig_create(char *transceivers_str)
int _net_if_ifconfig_create(char *transceivers_str)
{
char *transceiver_str;
transceiver_type_t transceivers = TRANSCEIVER_NONE;
@ -435,7 +438,7 @@ void _net_if_ifconfig_create(char *transceivers_str)
}
else {
create_usage();
return;
return 1;
}
transceiver_str = strtok(NULL, ",");
@ -443,16 +446,18 @@ void _net_if_ifconfig_create(char *transceivers_str)
if (!transceivers) {
create_usage();
return;
return 1;
}
iface = net_if_init_interface(NET_IF_L3P_RAW, transceivers);
if (iface < 0) {
puts("Maximum number of allowed interfaces reached.\n");
return 1;
}
else {
printf("Initialized interface %d\n", iface);
return 0;
}
}
@ -535,7 +540,7 @@ int _net_if_ifconfig_ipv6_addr_convert(net_if_addr_t *addr, void *addr_data,
return 1;
}
void _net_if_ifconfig_list(int if_id)
int _net_if_ifconfig_list(int if_id)
{
net_if_t *iface = net_if_get_interface(if_id);
transceiver_type_t transceivers;
@ -547,7 +552,7 @@ void _net_if_ifconfig_list(int if_id)
net_if_addr_t *addr_ptr = NULL;
if (!iface) {
return;
return 1;
}
transceivers = iface->transceivers;
@ -666,4 +671,6 @@ void _net_if_ifconfig_list(int if_id)
}
puts("");
return 0;
}

View File

@ -291,7 +291,7 @@ static void _netif_set(char *cmd_name, kernel_pid_t dev, char *key, char *value)
}
/* shell commands */
void _netif_send(int argc, char **argv)
int _netif_send(int argc, char **argv)
{
kernel_pid_t dev;
uint8_t addr[MAX_ADDR_LEN];
@ -302,7 +302,7 @@ void _netif_send(int argc, char **argv)
if (argc < 4) {
printf("usage: %s <if> <addr> <data>\n", argv[0]);
return;
return 1;
}
/* parse interface */
@ -310,7 +310,7 @@ void _netif_send(int argc, char **argv)
if (!_is_iface(dev)) {
puts("error: invalid interface given");
return;
return 1;
}
/* parse address */
@ -318,7 +318,7 @@ void _netif_send(int argc, char **argv)
if (addr_len == 0) {
puts("error: invalid address given");
return;
return 1;
}
/* put packet together */
@ -330,9 +330,11 @@ void _netif_send(int argc, char **argv)
ng_netif_hdr_set_dst_addr(nethdr, addr, addr_len);
/* and send it */
ng_netapi_send(dev, pkt);
return 0;
}
void _netif_config(int argc, char **argv)
int _netif_config(int argc, char **argv)
{
if (argc < 2) {
size_t numof;
@ -340,7 +342,7 @@ void _netif_config(int argc, char **argv)
for (size_t i = 0; i < numof; i++) {
_netif_list(ifs[i]);
return;
return 0;
}
}
else if (_is_number(argv[1])) {
@ -349,16 +351,16 @@ void _netif_config(int argc, char **argv)
if (_is_iface(dev)) {
if (argc < 3) {
_netif_list(dev);
return;
return 0;
}
else if (strcmp(argv[2], "set") == 0) {
if (argc < 5) {
_set_usage(argv[0]);
return;
return 0;
}
_netif_set(argv[0], dev, argv[3], argv[4]);
return;
return 0;
}
/* TODO implement add for IP addresses */
@ -369,4 +371,5 @@ void _netif_config(int argc, char **argv)
}
printf("usage: %s [<if_id> set <key> <value>]]\n", argv[0]);
return 1;
}

View File

@ -20,10 +20,12 @@
#include "ps.h"
void _ps_handler(int argc, char **argv)
int _ps_handler(int argc, char **argv)
{
(void) argc;
(void) argv;
thread_print_all();
return 0;
}

View File

@ -25,7 +25,7 @@
static char addr_str[IPV6_MAX_ADDR_STR_LEN];
void _rpl_route_handler(int argc, char **argv)
int _rpl_route_handler(int argc, char **argv)
{
(void) argc;
(void) argv;
@ -57,4 +57,6 @@ void _rpl_route_handler(int argc, char **argv)
puts("No routing table available");
}
puts("$");
return 0;
}

View File

@ -29,11 +29,12 @@
#include "periph/rtc.h"
void _alarm_handler(void *arg)
int _alarm_handler(void *arg)
{
(void) arg;
puts("The alarm rang");
return 0;
}
static int dow(int year, int month, int day)
@ -74,59 +75,70 @@ static int _parse_time(char **argv, struct tm *time)
return 0;
}
static void _print_time(struct tm *time)
static int _print_time(struct tm *time)
{
printf("%04i-%02i-%02i %02i:%02i:%02i\n",
time->tm_year + 1900, time->tm_mon + 1, time->tm_mday,
time->tm_hour, time->tm_min, time->tm_sec
);
return 0;
}
static void _rtc_getalarm(void)
static int _rtc_getalarm(void)
{
struct tm t;
if (rtc_get_alarm(&t) == 0) {
_print_time(&t);
return 0;
}
else {
puts("rtc: error getting alarm");
return 1;
}
}
static void _rtc_setalarm(char **argv)
static int _rtc_setalarm(char **argv)
{
struct tm now;
if (_parse_time(argv, &now) == 0) {
if (rtc_set_alarm(&now, _alarm_handler, NULL) == -1) {
puts("rtc: error setting alarm");
return 1;
}
return 0;
}
return 1;
}
static void _rtc_gettime(void)
static int _rtc_gettime(void)
{
struct tm t;
if (rtc_get_time(&t) == 0) {
_print_time(&t);
return 0;
}
else {
puts("rtc: error getting time");
return 1;
}
}
static void _rtc_settime(char **argv)
static int _rtc_settime(char **argv)
{
struct tm now;
if (_parse_time(argv, &now) == 0) {
if (rtc_set_time(&now) == -1) {
puts("rtc: error setting time");
return 1;
}
return 0;
}
return 1;
}
static void _rtc_usage(void)
static int _rtc_usage(void)
{
puts("usage: rtc <command> [arguments]");
puts("commands:");
@ -138,12 +150,14 @@ static void _rtc_usage(void)
puts("\tsetalarm YYYY-MM-DD HH:MM:SS\n\t\t\tset an alarm for the specified time");
puts("\tgettime\t\tprint the current time");
puts("\tsettime YYYY-MM-DD HH:MM:SS\n\t\t\tset the current time");
return 0;
}
void _rtc_handler(int argc, char **argv)
int _rtc_handler(int argc, char **argv)
{
if (argc < 2) {
_rtc_usage();
return 1;
}
else if (strncmp(argv[1], "init", 4) == 0) {
rtc_init();
@ -171,19 +185,22 @@ void _rtc_handler(int argc, char **argv)
}
else {
printf("unknown command: %s\n", argv[1]);
return 1;
}
return 0;
}
#else
#include <stdio.h>
void _rtc_handler(int argc, char **argv)
int _rtc_handler(int argc, char **argv)
{
(void) argc;
(void) argv;
puts("not implemented");
return 1;
}
#endif /* FEATURE_RTC */

View File

@ -28,7 +28,7 @@
extern float sht11_temperature_offset;
void _get_humidity_handler(int argc, char **argv)
int _get_humidity_handler(int argc, char **argv)
{
(void) argc;
(void) argv;
@ -39,14 +39,18 @@ void _get_humidity_handler(int argc, char **argv)
if (!success) {
printf("Error reading SHT11\n");
return 1;
}
else {
printf("Relative humidity: %5.2f%% / Temperature compensated humidity; %5.2f%%\n",
(double) sht11_val.relhum, (double) sht11_val.relhum_temp);
return 0;
}
}
void _get_temperature_handler(int argc, char **argv)
int _get_temperature_handler(int argc, char **argv)
{
(void) argc;
(void) argv;
@ -57,13 +61,17 @@ void _get_temperature_handler(int argc, char **argv)
if (!success) {
printf("Error reading SHT11\n");
return 1;
}
else {
printf("Temperature: %-6.2f°C\n", (double) sht11_val.temperature);
return 0;
}
}
void _get_weather_handler(int argc, char **argv)
int _get_weather_handler(int argc, char **argv)
{
(void) argc;
(void) argv;
@ -74,22 +82,30 @@ void _get_weather_handler(int argc, char **argv)
if (!success) {
printf("Error reading SHT11\n");
return 1;
}
else {
printf("Relative humidity: %5.2f%% / Temperature compensated humidity; %5.2f%% ",
(double) sht11_val.relhum, (double) sht11_val.relhum_temp);
printf("Temperature: %-6.2f°C\n", (double) sht11_val.temperature);
return 0;
}
}
void _set_offset_handler(int argc, char **argv)
int _set_offset_handler(int argc, char **argv)
{
if (argc != 2) {
printf("Usage: %s <OFFSET>\n", argv[0]);
return 1;
}
else {
sht11_temperature_offset = atoi(argv[1]);
printf("Temperature offset set to %f\n", (double) sht11_temperature_offset);
return 0;
}
}

View File

@ -20,10 +20,12 @@
#include "kernel.h"
void _reboot_handler(int argc, char **argv)
int _reboot_handler(int argc, char **argv)
{
(void) argc;
(void) argv;
(void) reboot(RB_AUTOBOOT);
return 0;
}

View File

@ -72,7 +72,7 @@
#endif
/* checked for type safety */
void _transceiver_get_set_address_handler(int argc, char **argv)
int _transceiver_get_set_address_handler(int argc, char **argv)
{
msg_t mesg;
transceiver_command_t tcmd;
@ -80,7 +80,7 @@ void _transceiver_get_set_address_handler(int argc, char **argv)
if (transceiver_pid == KERNEL_PID_UNDEF) {
puts("Transceiver not initialized");
return;
return 1;
}
tcmd.transceivers = _TC_TYPE;
@ -98,6 +98,8 @@ void _transceiver_get_set_address_handler(int argc, char **argv)
msg_send_receive(&mesg, &mesg, transceiver_pid);
printf("[transceiver] got address: %" PRIu16 "\n", a);
return 0;
}
#ifndef MODULE_NET_IF
@ -151,7 +153,7 @@ uint64_t _str_to_eui64(const char *eui64_str)
#endif
/* checked for type safety */
void _transceiver_get_set_long_addr_handler(int argc, char **argv)
int _transceiver_get_set_long_addr_handler(int argc, char **argv)
{
msg_t mesg;
transceiver_command_t tcmd;
@ -159,7 +161,7 @@ void _transceiver_get_set_long_addr_handler(int argc, char **argv)
if (transceiver_pid == KERNEL_PID_UNDEF) {
puts("Transceiver not initialized");
return;
return 1;
}
tcmd.transceivers = _TC_TYPE;
@ -183,11 +185,13 @@ void _transceiver_get_set_long_addr_handler(int argc, char **argv)
msg_send_receive(&mesg, &mesg, transceiver_pid);
printf("[transceiver] got EUI-64: %016"PRIx64"\n", a);
return 0;
}
/* checked for type safety */
void _transceiver_get_set_channel_handler(int argc, char **argv)
int _transceiver_get_set_channel_handler(int argc, char **argv)
{
msg_t mesg;
transceiver_command_t tcmd;
@ -195,7 +199,7 @@ void _transceiver_get_set_channel_handler(int argc, char **argv)
if (transceiver_pid == KERNEL_PID_UNDEF) {
puts("Transceiver not initialized");
return;
return 1;
}
tcmd.transceivers = _TC_TYPE;
@ -218,17 +222,19 @@ void _transceiver_get_set_channel_handler(int argc, char **argv)
else {
printf("[transceiver] Got channel: %" PRIi32 "\n", c);
}
return 0;
}
void _transceiver_send_handler(int argc, char **argv)
int _transceiver_send_handler(int argc, char **argv)
{
if (transceiver_pid == KERNEL_PID_UNDEF) {
puts("Transceiver not initialized");
return;
return 1;
}
if (argc < 3) {
printf("Usage:\t%s <ADDR> <MSG> [PAN]\n", argv[0]);
return;
return 1;
}
#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X
@ -280,18 +286,20 @@ void _transceiver_send_handler(int argc, char **argv)
msg_send_receive(&mesg, &mesg, transceiver_pid);
int8_t response = mesg.content.value;
printf("[transceiver] Packet sent: %" PRIi8 "\n", response);
return 0;
}
/* checked for type safety */
void _transceiver_monitor_handler(int argc, char **argv)
int _transceiver_monitor_handler(int argc, char **argv)
{
if (transceiver_pid == KERNEL_PID_UNDEF) {
puts("Transceiver not initialized");
return;
return 1;
}
else if (argc != 2) {
printf("Usage:\n%s <MODE>\n", argv[0]);
return;
return 1;
}
uint8_t m = atoi(argv[1]);
@ -306,14 +314,16 @@ void _transceiver_monitor_handler(int argc, char **argv)
mesg.type = SET_MONITOR;
msg_send(&mesg, transceiver_pid);
return 0;
}
/* checked for type safety */
void _transceiver_get_set_pan_handler(int argc, char **argv)
int _transceiver_get_set_pan_handler(int argc, char **argv)
{
if (transceiver_pid == KERNEL_PID_UNDEF) {
puts("Transceiver not initialized");
return;
return 1;
}
int32_t p;
@ -339,16 +349,18 @@ void _transceiver_get_set_pan_handler(int argc, char **argv)
else {
printf("[transceiver] Got pan: %" PRIi32 "\n", p);
}
return 0;
}
/* checked for type safety */
#ifdef DBG_IGNORE
void _transceiver_set_ignore_handler(int argc, char **argv)
int _transceiver_set_ignore_handler(int argc, char **argv)
{
if (transceiver_pid == KERNEL_PID_UNDEF) {
puts("Transceiver not initialized");
return;
return 1;
}
else if (argc < 2) {
printf("[transceiver] Ignored link layer addresses: ");
@ -362,7 +374,7 @@ void _transceiver_set_ignore_handler(int argc, char **argv)
}
else if (argc > 2) {
printf("Usage:\n%s <address>\n", argv[0]);
return;
return 1;
}
radio_address_t a;
@ -386,5 +398,7 @@ void _transceiver_set_ignore_handler(int argc, char **argv)
else {
printf("Success (added at index %" PRIi16 ").\n", response);
}
return 0;
}
#endif

View File

@ -33,7 +33,7 @@
#include <stdio.h>
extern void _x86_lspci(int argc, char **argv)
extern int _x86_lspci(int argc, char **argv)
{
(void) argc;
(void) argv;
@ -59,4 +59,6 @@ extern void _x86_lspci(int argc, char **argv)
vendor_name, device_name,
baseclass_name, subclass_name, d->class.revision_id);
}
return 0;
}

View File

@ -23,58 +23,58 @@
#include <stdlib.h>
#include "shell_commands.h"
extern void _reboot_handler(int argc, char **argv);
extern int _reboot_handler(int argc, char **argv);
#ifdef MODULE_CONFIG
extern void _id_handler(int argc, char **argv);
extern int _id_handler(int argc, char **argv);
#endif
#ifdef MODULE_LPC_COMMON
extern void _heap_handler(int argc, char **argv);
extern int _heap_handler(int argc, char **argv);
#endif
#ifdef MODULE_PS
extern void _ps_handler(int argc, char **argv);
extern int _ps_handler(int argc, char **argv);
#endif
#ifdef MODULE_SHT11
extern void _get_temperature_handler(int argc, char **argv);
extern void _get_humidity_handler(int argc, char **argv);
extern void _get_weather_handler(int argc, char **argv);
extern void _set_offset_handler(int argc, char **argv);
extern int _get_temperature_handler(int argc, char **argv);
extern int _get_humidity_handler(int argc, char **argv);
extern int _get_weather_handler(int argc, char **argv);
extern int _set_offset_handler(int argc, char **argv);
#endif
#ifdef MODULE_ISL29020
extern void _get_isl29020_init_handler(int argc, char **argv);
extern void _get_isl29020_read_handler(int argc, char **argv);
extern int _get_isl29020_init_handler(int argc, char **argv);
extern int _get_isl29020_read_handler(int argc, char **argv);
#endif
#ifdef MODULE_LPS331AP
extern void _get_lps331ap_init_handler(int argc, char **argv);
extern void _get_lps331ap_read_handler(int argc, char **argv);
extern int _get_lps331ap_init_handler(int argc, char **argv);
extern int _get_lps331ap_read_handler(int argc, char **argv);
#endif
#ifdef MODULE_L3G4200D
extern void _get_l3g4200d_init_handler(int argc, char **argv);
extern void _get_l3g4200d_read_handler(int argc, char **argv);
extern int _get_l3g4200d_init_handler(int argc, char **argv);
extern int _get_l3g4200d_read_handler(int argc, char **argv);
#endif
#ifdef MODULE_LSM303DLHC
extern void _get_lsm303dlhc_init_handler(int argc, char **argv);
extern void _get_lsm303dlhc_read_handler(int argc, char **argv);
extern int _get_lsm303dlhc_init_handler(int argc, char **argv);
extern int _get_lsm303dlhc_read_handler(int argc, char **argv);
#endif
#ifdef MODULE_LTC4150
extern void _get_current_handler(int argc, char **argv);
extern void _reset_current_handler(int argc, char **argv);
extern int _get_current_handler(int argc, char **argv);
extern int _reset_current_handler(int argc, char **argv);
#endif
#if FEATURE_PERIPH_RTC
extern void _rtc_handler(int argc, char **argv);
extern int _rtc_handler(int argc, char **argv);
#endif
#ifdef CPU_X86
extern void _x86_lspci(int argc, char **argv);
extern int _x86_lspci(int argc, char **argv);
#endif
/* configure available commands for each transceiver device: */
@ -94,68 +94,68 @@ extern void _x86_lspci(int argc, char **argv);
#endif
#else /* WITHOUT MODULE_TRANSCEIVER */
#ifdef MODULE_CC110X_LEGACY_CSMA
extern void _cc110x_get_set_address_handler(int argc, char **argv);
extern void _cc110x_get_set_channel_handler(int argc, char **argv);
extern int _cc110x_get_set_address_handler(int argc, char **argv);
extern int _cc110x_get_set_channel_handler(int argc, char **argv);
#endif
#endif
#ifdef MODULE_TRANSCEIVER
#ifdef _TC_ADDR
extern void _transceiver_get_set_address_handler(int argc, char **argv);
extern int _transceiver_get_set_address_handler(int argc, char **argv);
#endif
#ifdef _TC_LONG_ADDR
extern void _transceiver_get_set_long_addr_handler(int argc, char **argv);
extern int _transceiver_get_set_long_addr_handler(int argc, char **argv);
#endif
#ifdef _TC_CHAN
extern void _transceiver_get_set_channel_handler(int argc, char **argv);
extern int _transceiver_get_set_channel_handler(int argc, char **argv);
#endif
#ifdef _TC_SEND
extern void _transceiver_send_handler(int argc, char **argv);
extern int _transceiver_send_handler(int argc, char **argv);
#endif
#ifdef _TC_MON
extern void _transceiver_monitor_handler(int argc, char **argv);
extern int _transceiver_monitor_handler(int argc, char **argv);
#endif
#ifdef _TC_PAN
extern void _transceiver_get_set_pan_handler(int argc, char **argv);
extern int _transceiver_get_set_pan_handler(int argc, char **argv);
#endif
#ifdef _TC_IGN
extern void _transceiver_set_ignore_handler(int argc, char **argv);
extern int _transceiver_set_ignore_handler(int argc, char **argv);
#endif
#endif
#ifdef MODULE_L2_PING
extern void _l2_ping_req_handler(int argc, char **argv);
extern void _l2_ping_probe_handler(int argc, char **argv);
extern void _l2_ping_get_probe_handler(int argc, char **argv);
extern int _l2_ping_req_handler(int argc, char **argv);
extern int _l2_ping_probe_handler(int argc, char **argv);
extern int _l2_ping_get_probe_handler(int argc, char **argv);
#endif
#ifdef MODULE_NET_IF
extern void _net_if_ifconfig(int argc, char **argv);
extern int _net_if_ifconfig(int argc, char **argv);
#endif
#ifdef MODULE_RPL
extern void _rpl_route_handler(int argc, char **argv);
extern int _rpl_route_handler(int argc, char **argv);
#endif
#ifdef MODULE_MCI
extern void _get_sectorsize(int argc, char **argv);
extern void _get_blocksize(int argc, char **argv);
extern void _get_sectorcount(int argc, char **argv);
extern void _read_sector(int argc, char **argv);
extern void _read_bytes(int argc, char **argv);
extern int _get_sectorsize(int argc, char **argv);
extern int _get_blocksize(int argc, char **argv);
extern int _get_sectorcount(int argc, char **argv);
extern int _read_sector(int argc, char **argv);
extern int _read_bytes(int argc, char **argv);
#endif
#ifdef MODULE_RANDOM
extern void _mersenne_init(int argc, char **argv);
extern void _mersenne_get(int argc, char **argv);
extern int _mersenne_init(int argc, char **argv);
extern int _mersenne_get(int argc, char **argv);
#endif
#ifdef MODULE_NG_NETIF
#ifndef MODULE_NET_IF
extern void _netif_config(int argc, char **argv);
extern int _netif_config(int argc, char **argv);
#endif
#ifndef MODULE_TRANSCEIVER
extern void _netif_send(int argc, char **argv);
extern int _netif_send(int argc, char **argv);
#endif
#endif

View File

@ -55,9 +55,9 @@
static int shell_read(void);
static void shell_write(int);
static void cmd_send(int argc, char **argv);
static void cmd_print_regs(int argc, char **argv);
static void cmd_its(int argc, char **argv);
static int cmd_send(int argc, char **argv);
static int cmd_print_regs(int argc, char **argv);
static int cmd_its(int argc, char **argv);
void printbin(unsigned byte);
@ -182,7 +182,7 @@ void *nrf24l01p_rx_handler(void *arg)
/**
* @init transceiver
*/
void cmd_its(int argc, char **argv)
int cmd_its(int argc, char **argv)
{
(void) argc;
(void) argv;
@ -206,16 +206,16 @@ void cmd_its(int argc, char **argv)
/* setup device as receiver */
if (nrf24l01p_set_rxmode(&nrf24l01p_0) < 0) {
puts("Error in nrf24l01p_set_rxmode");
return;
return 1;
}
/* get and print all registers */
cmd_print_regs(0, 0);
return cmd_print_regs(0, 0);
}
/**
* @set TX mode
*/
void cmd_send(int argc, char **argv)
int cmd_send(int argc, char **argv)
{
(void) argc;
(void) argv;
@ -259,14 +259,16 @@ void cmd_send(int argc, char **argv)
/* setup device as receiver */
if (nrf24l01p_set_rxmode(&nrf24l01p_0) < 0) {
puts("Error in nrf24l01p_set_rxmode");
return;
return 1;
}
return 0;
}
/**
* @print registers
*/
void cmd_print_regs(int argc, char **argv)
int cmd_print_regs(int argc, char **argv)
{
(void) argc;
(void) argv;
@ -321,6 +323,8 @@ void cmd_print_regs(int argc, char **argv)
puts("REG_FEATURE: ");
print_register(REG_FEATURE, 1);
return 0;
}

View File

@ -31,7 +31,7 @@
static int i2c_dev = -1;
void cmd_init_master(int argc, char **argv)
int cmd_init_master(int argc, char **argv)
{
int dev, speed, res;
@ -48,7 +48,7 @@ void cmd_init_master(int argc, char **argv)
puts(" 2 -> SPEED_FAST (400kbit/s)");
puts(" 3 -> SPEED_FAST_PLUS (1Mbit/s)");
puts(" 4 -> SPEED_HIGH (3.4Mbit/s)\n");
return;
return 1;
}
dev = atoi(argv[1]);
@ -57,19 +57,21 @@ void cmd_init_master(int argc, char **argv)
res = i2c_init_master(dev, speed);
if (res == -1) {
puts("Error: Init: Given device not available");
return;
return 1;
}
else if (res == -2) {
puts("Error: Init: Unsupported speed value");
return;
return 1;
}
else {
printf("I2C_%i successfully initialized as master!\n", dev);
i2c_dev = dev;
}
return 0;
}
void cmd_init_slave(int argc, char **argv)
int cmd_init_slave(int argc, char **argv)
{
int dev, addr, res;
@ -81,7 +83,7 @@ void cmd_init_slave(int argc, char **argv)
printf(" %i -> I2C_%i\n", i, i);
}
puts(" ADDRESS: value between 0 and 127");
return;
return 1;
}
dev = atoi(argv[1]);
@ -90,19 +92,21 @@ void cmd_init_slave(int argc, char **argv)
res = i2c_init_slave(dev, addr);
if (res == -1) {
puts("Error: Init: Given device not available");
return;
return 1;
}
else if (res == -2) {
puts("Error: Init: Invalid address given");
return;
return 1;
}
else {
printf("I2C_%i successfully initialized as slave with address %i!\n", dev, addr);
i2c_dev = dev;
}
return 0;
}
void cmd_write(int argc, char **argv)
int cmd_write(int argc, char **argv)
{
int res;
uint8_t addr;
@ -111,12 +115,12 @@ void cmd_write(int argc, char **argv)
if (i2c_dev < 0) {
puts("Error: no I2C device was initialized");
return;
return 1;
}
if (argc < 3) {
puts("Error: not enough arguments given");
printf("Usage:\n%s: ADDR BYTE0 [BYTE1 [BYTE_n [...]]]\n", argv[0]);
return;
return 1;
}
addr = (uint8_t)atoi(argv[1]);
@ -139,13 +143,15 @@ void cmd_write(int argc, char **argv)
if (res < 0) {
puts("Error: no bytes were written");
return 1;
}
else {
printf("I2C_%i: successfully wrote %i bytes to the bus\n", i2c_dev, res);
return 0;
}
}
void cmd_write_reg(int argc, char **argv)
int cmd_write_reg(int argc, char **argv)
{
int res;
uint8_t addr, reg;
@ -154,12 +160,12 @@ void cmd_write_reg(int argc, char **argv)
if (i2c_dev < 0) {
puts("Error: no I2C device initialized");
return;
return 1;
}
if (length < 1) {
puts("Error: not enough arguments given");
printf("Usage:\n%s ADDR REG BYTE0 [BYTE1 ...]\n", argv[0]);
return;
return 1;
}
addr = (uint8_t)atoi(argv[1]);
@ -184,13 +190,15 @@ void cmd_write_reg(int argc, char **argv)
if (res < 1) {
puts("Error: no bytes were written");
return 1;
}
else {
printf("I2C_%i: successfully wrote %i bytes to register 0x%02x\n", i2c_dev, res, reg);
return 0;
}
}
void cmd_read(int argc, char **argv)
int cmd_read(int argc, char **argv)
{
int res;
uint8_t addr;
@ -199,12 +207,12 @@ void cmd_read(int argc, char **argv)
if (i2c_dev < 0) {
puts("Error: no I2C device initialized");
return;
return 1;
}
if (argc < 3) {
puts("Error: not enough arguments given");
printf("Usage:\n%s ADDR LENGTH]\n", argv[0]);
return;
return 1;
}
addr = (uint8_t)atoi(argv[1]);
@ -212,7 +220,7 @@ void cmd_read(int argc, char **argv)
if (length < 1 || length > BUFSIZE) {
puts("Error: invalid LENGTH parameter given\n");
return;
return 1;
}
else if (length == 1) {
printf("i2c_read_byte(I2C_%i, 0x%02x, char *res)\n", i2c_dev, addr);
@ -225,6 +233,7 @@ void cmd_read(int argc, char **argv)
if (res < 1) {
puts("Error: no bytes were read");
return 1;
}
else {
printf("I2C_%i: successfully read %i bytes:\n [", i2c_dev, res);
@ -232,10 +241,11 @@ void cmd_read(int argc, char **argv)
printf("0x%02x, ", (unsigned int)data[i]);
}
puts("])");
return 0;
}
}
void cmd_read_reg(int argc, char **argv)
int cmd_read_reg(int argc, char **argv)
{
int res;
uint8_t addr, reg;
@ -244,12 +254,12 @@ void cmd_read_reg(int argc, char **argv)
if (i2c_dev < 0) {
puts("Error: no I2C device initialized");
return;
return 1;
}
if (argc < 4) {
puts("Error: not enough arguments given");
printf("Usage:\n%s ADDR REG LENGTH]\n", argv[0]);
return;
return 1;
}
addr = (uint8_t)atoi(argv[1]);
@ -258,7 +268,7 @@ void cmd_read_reg(int argc, char **argv)
if (length < 1 || length > BUFSIZE) {
puts("Error: invalid LENGTH parameter given");
return;
return 1;
}
else if (length == 1) {
printf("i2c_read_reg(I2C_%i, 0x%02x, 0x%02x, char *res)\n", i2c_dev, addr, reg);
@ -271,6 +281,7 @@ void cmd_read_reg(int argc, char **argv)
if (res < 1) {
puts("Error: no bytes were read");
return 1;
}
else {
printf("I2C_%i: successfully read %i bytes from reg 0x%02x:\n [", i2c_dev, res, reg);
@ -278,6 +289,7 @@ void cmd_read_reg(int argc, char **argv)
printf("0x%02x, ", (unsigned int)data[i]);
}
puts("])");
return 0;
}
}

View File

@ -171,65 +171,65 @@ char slave_on_data(char data)
return 'e';
}
void cmd_init_master(int argc, char **argv)
int cmd_init_master(int argc, char **argv)
{
int res;
spi_master = -1;
if (parse_spi_dev(argc, argv) < 0) {
return;
return 1;
}
spi_acquire(spi_dev);
res = spi_init_master(spi_dev, spi_mode, spi_speed);
spi_release(spi_dev);
if (res < 0) {
printf("spi_init_master: error initializing SPI_%i device (code %i)\n", spi_dev, res);
return;
return 1;
}
res = gpio_init_out(spi_cs, GPIO_PULLUP);
if (res < 0){
printf("gpio_init_out: error initializing GPIO_%i as CS line (code %i)\n", spi_cs, res);
return;
return 1;
}
gpio_set(spi_cs);
spi_master = 1;
printf("SPI_%i successfully initialized as master, cs: GPIO_%i, mode: %i, speed: %i\n",
spi_dev, spi_cs, spi_mode, spi_speed);
return;
return 0;
}
void cmd_init_slave(int argc, char **argv)
int cmd_init_slave(int argc, char **argv)
{
int res;
spi_master = -1;
if (parse_spi_dev(argc, argv) < 0) {
return;
return 1;
}
spi_acquire(spi_dev);
res = spi_init_slave(spi_dev, spi_mode, slave_on_data);
spi_release(spi_dev);
if (res < 0) {
printf("spi_init_slave: error initializing SPI_%i device (code: %i)\n", spi_dev, res);
return;
return 1;
}
res = gpio_init_int(spi_cs, GPIO_NOPULL, GPIO_FALLING, slave_on_cs, 0);
if (res < 0){
printf("gpio_init_int: error initializing GPIO_%i as CS line (code %i)\n", spi_cs, res);
return;
return 1;
}
spi_master = 0;
printf("SPI_%i successfully initialized as slave, cs: GPIO_%i, mode: %i\n",
spi_dev, spi_cs, spi_mode);
return;
return 0;
}
void cmd_transfer(int argc, char **argv)
int cmd_transfer(int argc, char **argv)
{
int res;
char *hello = "Hello";
if (spi_master != 1) {
puts("error: node is not initialized as master, please do so first");
return;
return 1;
}
if (argc < 2) {
@ -249,18 +249,21 @@ void cmd_transfer(int argc, char **argv)
/* look at the results */
if (res < 0) {
printf("error: unable to transfer data to slave (code: %i)\n", res);
return 1;
}
else {
printf("Transfered %i bytes:\n", res);
print_bytes("MOSI", hello, res);
print_bytes("MISO", buffer, res);
return 0;
}
}
void cmd_print(int argc, char **argv)
int cmd_print(int argc, char **argv)
{
if (spi_master != 0) {
puts("error: node is not initialized as slave");
return 1;
}
else {
printf("Received %i bytes:\n", rx_counter);
@ -268,6 +271,7 @@ void cmd_print(int argc, char **argv)
}
rx_counter = 0;
memset(&rx_buffer, 0, 256);
return 0;
}
int shell_getchar(void)

View File

@ -28,26 +28,32 @@
#define SHELL_BUFSIZE (UART0_BUFSIZE)
static void print_teststart(int argc, char **argv)
static int print_teststart(int argc, char **argv)
{
(void) argc;
(void) argv;
printf("[TEST_START]\n");
return 0;
}
static void print_testend(int argc, char **argv)
static int print_testend(int argc, char **argv)
{
(void) argc;
(void) argv;
printf("[TEST_END]\n");
return 0;
}
static void print_echo(int argc, char **argv)
static int print_echo(int argc, char **argv)
{
for (int i = 0; i < argc; ++i) {
printf("“%s” ", argv[i]);
}
puts("");
return 0;
}
static int shell_readc(void)

View File

@ -54,49 +54,63 @@ bool proper_atoi(const char *a, int *i)
}
static void cmd_days_in(int argc, char **argv)
static int cmd_days_in(int argc, char **argv)
{
int mon;
if ((argc != 2) || (proper_atoi(argv[1], &mon) != 1) || (mon < 1) || (mon > 12)) {
printf("Usage: %s <Month[1..12]>\n", argv[0]);
return 1;
}
else {
printf("There are %d days in %.3s in common years.\n",
TM_MON_DAYS[mon - 1], MON_NAMES[mon - 1]);
return 0;
}
}
static void cmd_leap_year(int argc, char **argv)
static int cmd_leap_year(int argc, char **argv)
{
int year;
if ((argc != 2) || (proper_atoi(argv[1], &year) != 1)) {
printf("Usage: %s <Year>\n", argv[0]);
return 1;
}
else {
printf("Was %d a leap year? %.3s.\n",
year, BOOL_NAMES[tm_is_leap_year(year)]);
return 0;
}
}
static void cmd_doomsday(int argc, char **argv)
static int cmd_doomsday(int argc, char **argv)
{
int year;
if ((argc != 2) || (proper_atoi(argv[1], &year) != 1)) {
printf("Usage: %s <Year>\n", argv[0]);
return 1;
}
else {
printf("What weekday was MAR 0 of %d? %.3s.\n",
year, DAY_NAMES[tm_doomsday(year) % 7]);
return 0;
}
}
static void cmd_day(int argc, char **argv)
static int cmd_day(int argc, char **argv)
{
int year, mon, day;
if ((argc != 4) || (proper_atoi(argv[1], &year) != 1)
|| (proper_atoi(argv[2], &mon) != 1)
|| (proper_atoi(argv[3], &day) != 1)) {
printf("Usage: %s <Year> <Month[1..12]> <Day[1..31]>\n", argv[0]);
return 1;
}
else {
if (!tm_is_valid_date(year, mon - 1, day)) {
@ -107,6 +121,8 @@ static void cmd_day(int argc, char **argv)
tm_get_wyday(year, mon - 1, day, &wday, &yday);
printf("What weekday was %04d-%02d-%02d? The %d(th) day of the year was a %.3s.\n",
year, mon, day, yday + 1, DAY_NAMES[wday]);
return 0;
}
}