Browse Source

shell: Return-based error-handling for shell handlers

- Included the missing parts.
- Squashed with @authmillenon's commit
dev/timer
kushalsingh007 8 years ago
parent
commit
9aae656be9
  1. 50
      examples/ccn-lite-client/main.c
  2. 14
      examples/rpl_udp/helper.c
  3. 18
      examples/rpl_udp/rpl.c
  4. 12
      examples/rpl_udp/rpl_udp.h
  5. 16
      examples/rpl_udp/udp.c
  6. 2
      sys/include/ps.h
  7. 5
      sys/include/shell.h
  8. 16
      sys/shell/commands/sc_cc110x_legacy_csma.c
  9. 35
      sys/shell/commands/sc_disk.c
  10. 4
      sys/shell/commands/sc_heap.c
  11. 5
      sys/shell/commands/sc_id.c
  12. 11
      sys/shell/commands/sc_isl29020.c
  13. 20
      sys/shell/commands/sc_l2_ping.c
  14. 11
      sys/shell/commands/sc_l3g4200d.c
  15. 14
      sys/shell/commands/sc_lps331ap.c
  16. 15
      sys/shell/commands/sc_lsm303dlhc.c
  17. 8
      sys/shell/commands/sc_ltc4150.c
  18. 8
      sys/shell/commands/sc_mersenne.c
  19. 137
      sys/shell/commands/sc_net_if.c
  20. 21
      sys/shell/commands/sc_netif.c
  21. 4
      sys/shell/commands/sc_ps.c
  22. 4
      sys/shell/commands/sc_rpl.c
  23. 35
      sys/shell/commands/sc_rtc.c
  24. 24
      sys/shell/commands/sc_sht11.c
  25. 4
      sys/shell/commands/sc_sys.c
  26. 48
      sys/shell/commands/sc_transceiver.c
  27. 4
      sys/shell/commands/sc_x86_lspci.c
  28. 86
      sys/shell/commands/shell_commands.c
  29. 24
      tests/driver_nrf24l01p_lowlevel/main.c
  30. 56
      tests/periph_i2c/main.c
  31. 30
      tests/periph_spi/main.c
  32. 12
      tests/shell/main.c
  33. 24
      tests/struct_tm_utility/main.c

50
examples/ccn-lite-client/main.c

@ -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[] = {

14
examples/rpl_udp/helper.c

@ -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;
}

18
examples/rpl_udp/rpl.c

@ -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;
}

12
examples/rpl_udp/rpl_udp.h

@ -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

16
examples/rpl_udp/udp.c

@ -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;
}

2
sys/include/ps.h

@ -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
}

5
sys/include/shell.h

@ -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.

16
sys/shell/commands/sc_cc110x_legacy_csma.c

@ -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;
}
}

35
sys/shell/commands/sc_disk.c

@ -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;
}

4
sys/shell/commands/sc_heap.c

@ -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;
}

5
sys/shell/commands/sc_id.c

@ -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;
}

11
sys/shell/commands/sc_isl29020.c

@ -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;
}
}

20
sys/shell/commands/sc_l2_ping.c

@ -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;
}

11
sys/shell/commands/sc_l3g4200d.c

@ -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;
}
}

14
sys/shell/commands/sc_lps331ap.c

@ -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 */

15
sys/shell/commands/sc_lsm303dlhc.c

@ -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;
}
}

8
sys/shell/commands/sc_ltc4150.c

@ -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;
}

8
sys/shell/commands/sc_mersenne.c

@ -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;
}

137
sys/shell/commands/sc_net_if.c

@ -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) {