diff --git a/cpu/mc1322x/maca/include/maca.h b/cpu/mc1322x/maca/include/maca.h index 10fe7fc7dd..94956467d9 100644 --- a/cpu/mc1322x/maca/include/maca.h +++ b/cpu/mc1322x/maca/include/maca.h @@ -10,9 +10,11 @@ #ifndef MACA_H_ #define MACA_H_ +#include + +#include "radio/types.h" #include "maca_packet.h" -#include /*********************************************************/ /* function definitions */ @@ -29,8 +31,8 @@ void maca_check ( void ); /* functions to configure MACA */ void maca_set_power ( uint8_t power ); void maca_set_channel ( uint8_t channel ); -uint16_t maca_set_address ( uint16_t addr ); -uint16_t maca_get_address ( void ); +radio_address_t maca_set_address (radio_address_t addr ); +radio_address_t maca_get_address ( void ); uint16_t maca_set_pan(uint16_t pan); uint16_t maca_get_pan(void); diff --git a/cpu/mc1322x/maca/maca.c b/cpu/mc1322x/maca/maca.c index 9939157817..cb510b9397 100644 --- a/cpu/mc1322x/maca/maca.c +++ b/cpu/mc1322x/maca/maca.c @@ -7,12 +7,12 @@ * * This file is part of RIOT. */ +#include #include "maca.h" #include "maca_packet.h" #include "nvm.h" #include "mc1322x.h" -#include // number of packets in the maca_packet_pool #ifndef MACA_NUM_PACKETS @@ -897,7 +897,7 @@ void maca_set_channel ( uint8_t chan ) { } } -uint16_t maca_set_address ( uint16_t addr ) { +radio_address_t maca_set_address (radio_address_t addr) { safe_irq_disable ( INT_NUM_MACA ); MACA->MAC16ADDR = addr; @@ -910,7 +910,7 @@ uint16_t maca_set_address ( uint16_t addr ) { return MACA->MAC16ADDR; } -uint16_t maca_get_address ( void ) { +radio_address_t maca_get_address ( void ) { return MACA->MAC16ADDR; } diff --git a/drivers/at86rf231/at86rf231.c b/drivers/at86rf231/at86rf231.c index dfd3ede56a..32bb3edf33 100644 --- a/drivers/at86rf231/at86rf231.c +++ b/drivers/at86rf231/at86rf231.c @@ -90,7 +90,7 @@ void at86rf231_rx_irq(void) at86rf231_rx_handler(); } -uint16_t at86rf231_set_address(uint16_t address) +radio_address_t at86rf231_set_address(radio_address_t address) { radio_address = address; @@ -100,7 +100,7 @@ uint16_t at86rf231_set_address(uint16_t address) return radio_address; } -uint16_t at86rf231_get_address(void) +radio_address_t at86rf231_get_address(void) { return radio_address; } diff --git a/drivers/cc2420/cc2420.c b/drivers/cc2420/cc2420.c index d52db549d3..78297b546f 100644 --- a/drivers/cc2420/cc2420.c +++ b/drivers/cc2420/cc2420.c @@ -124,7 +124,7 @@ uint16_t cc2420_get_channel(void) return ((cc2420_read_reg(CC2420_REG_FSCTRL) - 357) / 5) + 11; } -uint16_t cc2420_set_address(uint16_t addr) +radio_address_t cc2420_set_address(radio_address_t addr) { uint8_t buf[2]; buf[0] = (uint8_t)(addr & 0xFF); @@ -149,7 +149,7 @@ uint64_t cc2420_set_address_long(uint64_t addr) return addr; } -uint16_t cc2420_get_address(void) +radio_address_t cc2420_get_address(void) { uint16_t addr; cc2420_read_ram(CC2420_RAM_SHORTADR, (uint8_t *)&addr, sizeof(addr)); diff --git a/drivers/include/at86rf231.h b/drivers/include/at86rf231.h index 263469b4b2..ee01c47778 100644 --- a/drivers/include/at86rf231.h +++ b/drivers/include/at86rf231.h @@ -4,6 +4,8 @@ #include #include +#include "radio/types.h" + #include "ieee802154_frame.h" #include "at86rf231_arch.h" @@ -42,8 +44,8 @@ uint8_t at86rf231_get_channel(void); uint16_t at86rf231_set_pan(uint16_t pan); uint16_t at86rf231_get_pan(void); -uint16_t at86rf231_set_address(uint16_t address); -uint16_t at86rf231_get_address(void); +radio_address_t at86rf231_set_address(radio_address_t address); +radio_address_t at86rf231_get_address(void); uint64_t at86rf231_get_address_long(void); uint64_t at86rf231_set_address_long(uint64_t address); diff --git a/drivers/include/cc2420.h b/drivers/include/cc2420.h index 4f239a3b39..336e1cd9ee 100644 --- a/drivers/include/cc2420.h +++ b/drivers/include/cc2420.h @@ -79,6 +79,8 @@ Frame type value: #include "ieee802154_frame.h" #include "cc2420_settings.h" +#include "radio/types.h" + #define CC2420_MAX_PKT_LENGTH 127 #define CC2420_MAX_DATA_LENGTH (118) @@ -144,7 +146,7 @@ uint16_t cc2420_get_channel(void); * * @return The set address after calling. */ -uint16_t cc2420_set_address(uint16_t addr); +radio_address_t cc2420_set_address(radio_address_t addr); /** * @brief Gets the current short address of the cc2420. @@ -152,7 +154,7 @@ uint16_t cc2420_set_address(uint16_t addr); * @return The current short address. * */ -uint16_t cc2420_get_address(void); +radio_address_t cc2420_get_address(void); /** * @brief Sets the IEEE long address of the cc2420. diff --git a/sys/shell/commands/Makefile b/sys/shell/commands/Makefile index 290af6ebd5..4792e1aee3 100644 --- a/sys/shell/commands/Makefile +++ b/sys/shell/commands/Makefile @@ -1,16 +1,12 @@ SRC = shell_commands.c sc_id.c -ifneq (,$(findstring cc110x_ng,$(USEMODULE))) - SRC += sc_cc110x_ng.c -endif -ifneq (,$(findstring cc2420,$(USEMODULE))) - SRC += sc_cc2420.c +ifneq (,$(findstring transceiver,$(USEMODULE))) + SRC += sc_transceiver.c endif ifneq (,$(findstring cc110x,$(USEMODULE))) - SRC += sc_cc1100.c -endif -ifneq (,$(findstring nativenet,$(USEMODULE))) - SRC += sc_nativenet.c + ifeq (,$(findstring transceiver,$(USEMODULE))) + SRC += sc_cc1100.c + endif endif ifneq (,$(findstring mci,$(USEMODULE))) SRC += sc_disk.c diff --git a/sys/shell/commands/sc_cc1100.c b/sys/shell/commands/sc_cc1100.c index 7d9bc73dc3..cca1a581b3 100644 --- a/sys/shell/commands/sc_cc1100.c +++ b/sys/shell/commands/sc_cc1100.c @@ -1,5 +1,5 @@ /** - * Shell commands for cc110x driver + * Shell commands for the cc110x driver without a transceiver * * Copyright (C) 2013 INRIA. * @@ -10,106 +10,19 @@ * @ingroup shell_commands * @{ * @file sc_cc1100.c - * @brief provides shell commands to configure cc110x driver + * @brief provides shell commands to configure the cc110x driver * @author Oliver Hahm + * @author Ludwig Ortmann * @} */ #include #include #include + #include "cc110x.h" -#ifdef MODULE_CC110X -#include "msg.h" -#include "transceiver.h" -#ifdef MODULE_TRANSCEIVER -#define TEXT_SIZE CC1100_MAX_DATA_LENGTH - -char text_msg[TEXT_SIZE]; -msg_t mesg; -transceiver_command_t tcmd; - -void _cc1100_get_set_address_handler(char *addr) -{ - int16_t a; - - tcmd.transceivers = TRANSCEIVER_CC1100; - tcmd.data = &a; - mesg.content.ptr = (char *) &tcmd; - a = atoi(addr + 5); - - if (strlen(addr) > 5) { - printf("[cc110x] Trying to set address %i\n", a); - mesg.type = SET_ADDRESS; - } - else { - mesg.type = GET_ADDRESS; - } - - msg_send_receive(&mesg, &mesg, transceiver_pid); - printf("[cc110x] Got address: %i\n", a); -} - -void _cc1100_get_set_channel_handler(char *chan) -{ - int16_t c; - - tcmd.transceivers = TRANSCEIVER_CC1100; - tcmd.data = &c; - mesg.content.ptr = (char *) &tcmd; - c = atoi(chan + 5); - - if (strlen(chan) > 5) { - printf("[cc110x] Trying to set channel %i\n", c); - mesg.type = SET_CHANNEL; - } - else { - mesg.type = GET_CHANNEL; - } - - msg_send_receive(&mesg, &mesg, transceiver_pid); - printf("[cc110x] Got channel: %i\n", c); -} - -void _cc1100_send_handler(char *pkt) -{ - radio_packet_t p; - uint32_t response; - uint16_t addr; - char *tok; - - tcmd.transceivers = TRANSCEIVER_CC1100; - tcmd.data = &p; - - tok = strtok(pkt + 7, " "); - - if (tok) { - addr = atoi(tok); - tok = strtok(NULL, " "); - - if (tok) { - memset(text_msg, 0, TEXT_SIZE); - memcpy(text_msg, tok, strlen(tok)); - /* if (sscanf(pkt, "txtsnd %hu %s", &(addr), text_msg) == 2) {*/ - p.data = (uint8_t *) text_msg; - p.length = strlen(text_msg) + 1; - p.dst = addr; - mesg.type = SND_PKT; - mesg.content.ptr = (char *) &tcmd; - printf("[cc110x] Sending packet of length %u to %hu: %s\n", p.length, p.dst, (char *) p.data); - msg_send_receive(&mesg, &mesg, transceiver_pid); - response = mesg.content.value; - printf("[cc110x] Packet sent: %lu\n", response); - return; - } - } - - puts("Usage:\ttxtsnd "); -} - -#else void _cc110x_get_set_address_handler(char *addr) { int16_t a; @@ -153,5 +66,3 @@ void _cc110x_get_set_channel_handler(char *addr) printf("[cc1100] Got address: %i\n", cc1100_get_channel()); } } -#endif -#endif diff --git a/sys/shell/commands/sc_cc110x_ng.c b/sys/shell/commands/sc_cc110x_ng.c deleted file mode 100644 index 26ad8aedc0..0000000000 --- a/sys/shell/commands/sc_cc110x_ng.c +++ /dev/null @@ -1,126 +0,0 @@ -/** - * Shell commands for cc110x_ng driver - * - * Copyright (C) 2013 INRIA. - * - * This file is subject to the terms and conditions of the GNU Lesser General - * Public License. See the file LICENSE in the top level directory for more - * details. - * - * @ingroup shell_commands - * @{ - * @file sc_cc110x_ng.c - * @brief provides shell commands to configure cc110x_ng driver - * @author Oliver Hahm - * @} - */ - -#include -#include -#include -#include -#include "transceiver.h" -#include "cc110x_ng.h" -#include "msg.h" - -#define TEXT_SIZE CC1100_MAX_DATA_LENGTH - -char text_msg[TEXT_SIZE]; -msg_t mesg; -transceiver_command_t tcmd; - -void _cc110x_ng_get_set_address_handler(char *addr) -{ - int16_t a; - - tcmd.transceivers = TRANSCEIVER_CC1100; - tcmd.data = &a; - mesg.content.ptr = (char *) &tcmd; - a = atoi(addr + 5); - - if (strlen(addr) > 5) { - printf("[cc110x] Trying to set address %i\n", a); - mesg.type = SET_ADDRESS; - } - else { - mesg.type = GET_ADDRESS; - } - - msg_send_receive(&mesg, &mesg, transceiver_pid); - printf("[cc110x] Got address: %i\n", a); -} - -void _cc110x_ng_get_set_channel_handler(char *chan) -{ - int16_t c; - - tcmd.transceivers = TRANSCEIVER_CC1100; - tcmd.data = &c; - mesg.content.ptr = (char *) &tcmd; - c = atoi(chan + 5); - - if (strlen(chan) > 5) { - printf("[cc110x] Trying to set channel %i\n", c); - mesg.type = SET_CHANNEL; - } - else { - mesg.type = GET_CHANNEL; - } - - msg_send_receive(&mesg, &mesg, transceiver_pid); - printf("[cc110x] Got channel: %i\n", c); -} - -void _cc110x_ng_send_handler(char *pkt) -{ - radio_packet_t p; - uint32_t response; - uint16_t addr; - char *tok; - - tcmd.transceivers = TRANSCEIVER_CC1100; - tcmd.data = &p; - - tok = strtok(pkt + 7, " "); - - if (tok) { - addr = atoi(tok); - tok = strtok(NULL, " "); - - if (tok) { - memset(text_msg, 0, TEXT_SIZE); - memcpy(text_msg, tok, strlen(tok)); - p.data = (uint8_t *) text_msg; - p.length = strlen(text_msg) + 1; - p.dst = addr; - mesg.type = SND_PKT; - mesg.content.ptr = (char *)&tcmd; - printf("[cc110x] Sending packet of length %u to %u: %s\n", p.length, p.dst, (char*) p.data); - msg_send_receive(&mesg, &mesg, transceiver_pid); - response = mesg.content.value; - printf("[cc110x] Packet sent: %" PRIu32 "\n", response); - return; - } - } - - puts("Usage:\ttxtsnd "); -} - -void _cc110x_ng_monitor_handler(char *mode) -{ - unsigned int m; - - tcmd.transceivers = TRANSCEIVER_CC1100; - tcmd.data = &m; - mesg.content.ptr = (char *) &tcmd; - m = atoi(mode + 8); - - if (strlen(mode) > 8) { - printf("Setting monitor mode: %u\n", m); - mesg.type = SET_MONITOR; - msg_send(&mesg, transceiver_pid, 1); - } - else { - puts("Usage:\nmonitor "); - } -} diff --git a/sys/shell/commands/sc_cc2420.c b/sys/shell/commands/sc_cc2420.c deleted file mode 100644 index 03690761c0..0000000000 --- a/sys/shell/commands/sc_cc2420.c +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (C) 2013 Milan Babel - * - * This file is subject to the terms and conditions of the GNU Lesser General - * Public License. See the file LICENSE in the top level directory for more - * details. - */ - -/** - * @ingroup shell_commands - * @{ - * - * @file - * @brief provides shell commands to configure cc2420 driver - * - * @author Milan Babel - * - * @} - */ - -#include -#include -#include -#include "transceiver.h" -#include "cc2420.h" -#include "msg.h" - -#define TEXT_SIZE CC2420_MAX_DATA_LENGTH - -char text_msg[TEXT_SIZE]; -msg_t mesg; -transceiver_command_t tcmd; - -void _cc2420_get_set_address_handler(char *addr) { - uint16_t a; - - tcmd.transceivers = TRANSCEIVER_CC2420; - tcmd.data = &a; - mesg.content.ptr = (char*) &tcmd; - a = atoi(addr+5); - if (strlen(addr) > 5) { - printf("[cc2420] Trying to set address %i\n", a); - mesg.type = SET_ADDRESS; - } - else { - mesg.type = GET_ADDRESS; - } - msg_send_receive(&mesg, &mesg, transceiver_pid); - printf("[cc2420] Got address: %i\n", a); -} - -void _cc2420_get_set_channel_handler(char *chan) { - int16_t c; - - tcmd.transceivers = TRANSCEIVER_CC2420; - tcmd.data = &c; - mesg.content.ptr = (char*) &tcmd; - c = atoi(chan+5); - if (strlen(chan) > 5) { - printf("[cc2420] Trying to set channel %i\n", c); - mesg.type = SET_CHANNEL; - } - else { - mesg.type = GET_CHANNEL; - } - msg_send_receive(&mesg, &mesg, transceiver_pid); - printf("[cc2420] Got channel: %i\n", c); -} - -void _cc2420_get_set_pan_handler(char *pan) { - uint16_t p; - - tcmd.transceivers = TRANSCEIVER_CC2420; - tcmd.data = &p; - mesg.content.ptr = (char*) &tcmd; - p = atoi(pan+4); - if (strlen(pan) > 4) { - printf("[cc2420] Trying to set pan %i\n", p); - mesg.type = SET_PAN; - } - else { - mesg.type = GET_PAN; - } - msg_send_receive(&mesg, &mesg, transceiver_pid); - printf("[cc2420] Got pan: %i\n", p); -} - -void _cc2420_send_handler(char *pkt) { - radio_packet_t p; - uint32_t response; - uint16_t addr; - char *tok; - - tcmd.transceivers = TRANSCEIVER_CC2420; - tcmd.data = &p; - - tok = strtok(pkt+7, " "); - if (tok) { - addr = atoi(tok); - tok = strtok(NULL, " "); - if (tok) { - memset(text_msg, 0, TEXT_SIZE); - memcpy(text_msg, tok, strlen(tok)); - /* if (sscanf(pkt, "txtsnd %hu %s", &(addr), text_msg) == 2) {*/ - p.data = (uint8_t*) text_msg; - p.length = strlen(text_msg) + 1; - p.dst = addr; - mesg.type = SND_PKT; - mesg.content.ptr = (char*) &tcmd; - printf("[cc2420] Sending packet of length %u to %u: %s\n", p.length, p.dst, (char*) p.data); - msg_send_receive(&mesg, &mesg, transceiver_pid); - response = mesg.content.value; - printf("[cc2420] Packet sent: %lu\n", response); - return; - } - } - puts("Usage:\ttxtsnd "); -} - -void _cc2420_monitor_handler(char *mode) { - unsigned int m; - - tcmd.transceivers = TRANSCEIVER_CC2420; - tcmd.data = &m; - mesg.content.ptr = (char*) &tcmd; - m = atoi(mode+8); - if (strlen(mode) > 8) { - printf("Setting monitor mode: %u\n", m); - mesg.type = SET_MONITOR; - msg_send(&mesg, transceiver_pid, 1); - } - else { - puts("Usage:\nmonitor "); - } -} diff --git a/sys/shell/commands/sc_nativenet.c b/sys/shell/commands/sc_nativenet.c deleted file mode 100644 index 3fa30712cd..0000000000 --- a/sys/shell/commands/sc_nativenet.c +++ /dev/null @@ -1,133 +0,0 @@ -/** - * Shell commands for native transceiver - * - * Copyright (C) 2013 Ludwig Ortmann. - * - * This file is subject to the terms and conditions of the GNU Lesser General - * Public License. See the file LICENSE in the top level directory for more - * details. - * - * @ingroup shell_commands - * @{ - * @file sc_nativenet.c - * @brief provides shell commands to configure nativenet transceiver - * @author Ludwig Ortmann - * @} - */ - -#include -#include -#include -#include - -#include "transceiver.h" -#include "nativenet.h" -#include "msg.h" - -#define TEXT_SIZE (255) /* XXX: this aint enough for everybody */ - -void _nativenet_get_set_address_handler(char *addr) -{ - msg_t mesg; - transceiver_command_t tcmd; - uint16_t a; - - tcmd.transceivers = TRANSCEIVER_NATIVE; - tcmd.data = &a; - mesg.content.ptr = (char *) &tcmd; - a = atoi(addr + 5); - - if (strlen(addr) > 5) { - printf("[nativenet] trying to set address %"PRIu16"\n", a); - mesg.type = SET_ADDRESS; - } - else { - mesg.type = GET_ADDRESS; - } - - msg_send_receive(&mesg, &mesg, transceiver_pid); - printf("[nativenet] got address: %"PRIu16"\n", a); -} - -void _nativenet_get_set_channel_handler(char *chan) -{ - msg_t mesg; - transceiver_command_t tcmd; - uint8_t c; - - tcmd.transceivers = TRANSCEIVER_NATIVE; - tcmd.data = &c; - mesg.content.ptr = (char *) &tcmd; - c = atoi(chan + 5); - - if (strlen(chan) > 5) { - printf("[nativenet] Trying to set channel %"PRIu8"\n", c); - mesg.type = SET_CHANNEL; - } - else { - mesg.type = GET_CHANNEL; - } - - msg_send_receive(&mesg, &mesg, transceiver_pid); - printf("[nativenet] Got channel: %"PRIu8"\n", c); -} - -void _nativenet_send_handler(char *pkt) -{ - msg_t mesg; - transceiver_command_t tcmd; - char text_msg[TEXT_SIZE]; - - radio_packet_t p; - uint32_t response; - uint16_t addr; - char *tok; - - tcmd.transceivers = TRANSCEIVER_NATIVE; - tcmd.data = &p; - - tok = strtok(pkt + 7, " "); - - if (tok) { - addr = atoi(tok); - tok = strtok(NULL, " "); - - if (tok) { - memset(text_msg, 0, TEXT_SIZE); - memcpy(text_msg, tok, strlen(tok)); - p.data = (uint8_t *) text_msg; - p.length = strlen(text_msg) + 1; - p.dst = addr; - mesg.type = SND_PKT; - mesg.content.ptr = (char *)&tcmd; - printf("[nativenet] Sending packet of length %"PRIu16" to %"PRIu16": %s\n", p.length, p.dst, (char*) p.data); - msg_send_receive(&mesg, &mesg, transceiver_pid); - response = mesg.content.value; - printf("[nativenet] Packet sent: %"PRIi8"\n", response); - return; - } - } - - puts("Usage:\ttxtsnd "); -} - -void _nativenet_monitor_handler(char *mode) -{ - msg_t mesg; - transceiver_command_t tcmd; - uint8_t m; - - tcmd.transceivers = TRANSCEIVER_NATIVE; - tcmd.data = &m; - mesg.content.ptr = (char *) &tcmd; - m = atoi(mode + 8); - - if (strlen(mode) > 8) { - printf("Setting monitor mode: %"PRIu8"\n", m); - mesg.type = SET_MONITOR; - msg_send(&mesg, transceiver_pid, 1); - } - else { - puts("Usage:\nmonitor "); - } -} diff --git a/sys/shell/commands/sc_transceiver.c b/sys/shell/commands/sc_transceiver.c new file mode 100644 index 0000000000..ee0fdff39c --- /dev/null +++ b/sys/shell/commands/sc_transceiver.c @@ -0,0 +1,249 @@ +/** + * Shell commands for transceiver module + * + * Copyright (C) 2013 Ludwig Ortmann. + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License. See the file LICENSE in the top level directory for more + * details. + * + * @ingroup shell_commands + * @{ + * @file sc_transceiver.c + * @brief provides shell commands to configure the transceiver + * @author Oliver Hahm + * @author Ludwig Ortmann + * @} + */ + +#include +#include +#include +#include + +#include "transceiver.h" +#include "msg.h" + +#if defined( MODULE_CC110X ) +#include "cc1100-interface.h" +#define TEXT_SIZE CC1100_MAX_DATA_LENGTH +#define _TC_TYPE TRANSCEIVER_CC1100 + +#elif defined( MODULE_CC110X_NG ) +#include "cc110x_ng.h" +#define TEXT_SIZE CC1100_MAX_DATA_LENGTH +#define _TC_TYPE TRANSCEIVER_CC1100 + +#elif defined( MODULE_CC2420 ) +#include "cc2420.h" +#define TEXT_SIZE CC2420_MAX_DATA_LENGTH +#define _TC_TYPE TRANSCEIVER_CC2420 + +#elif defined( MODULE_NATIVENET ) +#include "nativenet.h" +#define TEXT_SIZE NATIVE_MAX_DATA_LENGTH +#define _TC_TYPE TRANSCEIVER_NATIVE +#endif + + +/* checked for type safety */ +void _transceiver_get_set_address_handler(char *addr) +{ + msg_t mesg; + transceiver_command_t tcmd; + radio_address_t a; + + if (transceiver_pid < 0) { + puts("Transceiver not initialized"); + return; + } + + tcmd.transceivers = _TC_TYPE; + tcmd.data = &a; + mesg.content.ptr = (char *) &tcmd; + + if (strlen(addr) > 5) { + a = atoi(addr + 5); + printf("[transceiver] trying to set address %"PRIu16"\n", a); + mesg.type = SET_ADDRESS; + } + else { + mesg.type = GET_ADDRESS; + } + + msg_send_receive(&mesg, &mesg, transceiver_pid); + printf("[transceiver] got address: %"PRIu16"\n", a); +} + +/* checked for type safety */ +void _transceiver_get_set_channel_handler(char *chan) +{ + msg_t mesg; + transceiver_command_t tcmd; + int32_t c; + + if (transceiver_pid < 0) { + puts("Transceiver not initialized"); + return; + } + + tcmd.transceivers = _TC_TYPE; + tcmd.data = &c; + mesg.content.ptr = (char *) &tcmd; + + if (strlen(chan) > 5) { + c = atoi(chan + 5); + printf("[transceiver] Trying to set channel %"PRIi32"\n", c); + mesg.type = SET_CHANNEL; + } + else { + mesg.type = GET_CHANNEL; + } + + msg_send_receive(&mesg, &mesg, transceiver_pid); + if (c == -1) { + puts("[transceiver] Error setting/getting channel"); + } + else { + printf("[transceiver] Got channel: %"PRIi32"\n", c); + } +} + +void _transceiver_send_handler(char *pkt) +{ + msg_t mesg; + transceiver_command_t tcmd; + char text_msg[TEXT_SIZE]; + + radio_packet_t p; + int8_t response; + radio_address_t addr; + char *tok; + + if (transceiver_pid < 0) { + puts("Transceiver not initialized"); + return; + } + + tcmd.transceivers = _TC_TYPE; + tcmd.data = &p; + + tok = strtok(pkt + 7, " "); + + if (tok) { + addr = atoi(tok); + tok = strtok(NULL, " "); + + if (tok) { + memset(text_msg, 0, TEXT_SIZE); + memcpy(text_msg, tok, strlen(tok)); + p.data = (uint8_t *) text_msg; + p.length = strlen(text_msg) + 1; + p.dst = addr; + mesg.type = SND_PKT; + mesg.content.ptr = (char *)&tcmd; + printf("[transceiver] Sending packet of length %"PRIu16" to %"PRIu16": %s\n", p.length, p.dst, (char*) p.data); + msg_send_receive(&mesg, &mesg, transceiver_pid); + response = mesg.content.value; + printf("[transceiver] Packet sent: %"PRIi8"\n", response); + return; + } + } + + puts("Usage:\ttxtsnd "); +} + +/* checked for type safety */ +void _transceiver_monitor_handler(char *mode) +{ + msg_t mesg; + transceiver_command_t tcmd; + uint8_t m; + + if (transceiver_pid < 0) { + puts("Transceiver not initialized"); + return; + } + + tcmd.transceivers = _TC_TYPE; + tcmd.data = &m; + mesg.content.ptr = (char *) &tcmd; + + if (strlen(mode) > 8) { + m = atoi(mode + 8); + printf("Setting monitor mode: %"PRIu8"\n", m); + mesg.type = SET_MONITOR; + msg_send(&mesg, transceiver_pid, 1); + } + else { + puts("Usage:\nmonitor "); + } +} + +/* checked for type safety */ +void _transceiver_get_set_pan_handler(char *pan) { + transceiver_command_t tcmd; + msg_t mesg; + int32_t p; + + if (transceiver_pid < 0) { + puts("Transceiver not initialized"); + return; + } + + tcmd.transceivers = _TC_TYPE; + tcmd.data = &p; + mesg.content.ptr = (char*) &tcmd; + if (strlen(pan) > 4) { + p = atoi(pan+4); + printf("[transceiver] Trying to set pan %"PRIi32"\n", p); + mesg.type = SET_PAN; + } + else { + mesg.type = GET_PAN; + } + msg_send_receive(&mesg, &mesg, transceiver_pid); + if (p == -1) { + puts("[transceiver] Error setting/getting pan"); + } + else { + printf("[transceiver] Got pan: %"PRIi32"\n", p); + } +} + +/* checked for type safety */ +#ifdef DBG_IGNORE +void _transceiver_set_ignore_handler(char *addr) +{ + transceiver_command_t tcmd; + msg_t mesg; + radio_address_t a; + int16_t response; + + if (transceiver_pid < 0) { + puts("Transceiver not initialized"); + return; + } + + tcmd.transceivers = _TC_TYPE; + tcmd.data = &a; + mesg.content.ptr = (char*) &tcmd; + + if (strlen(addr) > 4) { + a = atoi(addr + 4); + printf("[transceiver] trying to add address %"PRIu16" to the ignore list \n", a); + mesg.type = DBG_IGN; + msg_send_receive(&mesg, &mesg, transceiver_pid); + response = a; + if (response == -1) { + printf("Error: ignore list full\n"); + } + else { + printf("Success (added at index %"PRIi16").\n", response); + } + } + else { + puts("Usage:\nign
"); + } +} +#endif diff --git a/sys/shell/commands/shell_commands.c b/sys/shell/commands/shell_commands.c index cd8749baf0..a2aa5f038b 100644 --- a/sys/shell/commands/shell_commands.c +++ b/sys/shell/commands/shell_commands.c @@ -14,6 +14,7 @@ * @brief sets up the system shell command struct * @author Oliver Hahm * @author Zakaria Kasmi + * @author Ludwig Ortmann * * @note $Id: shell_commands.c 3855 2013-09-05 12:54:57 kasmi $ * @} @@ -45,42 +46,46 @@ extern void _get_current_handler(char *unused); extern void _reset_current_handler(char *unused); #endif -#ifdef MODULE_CC110X + +/* configure available commands for each transceiver device: */ #ifdef MODULE_TRANSCEIVER -extern void _cc1100_get_set_address_handler(char *addr); -extern void _cc1100_get_set_channel_handler(char *chan); -extern void _cc1100_send_handler(char *pkt); -#else +#ifdef DBG_IGNORE +#define _TC_IGN +#endif +#if (defined(MODULE_CC110X_NG) || defined(MODULE_CC2420) || defined(MODULE_NATIVENET)) +#define _TC_ADDR +#define _TC_CHAN +#define _TC_MON +#define _TC_SEND +#endif +#if (defined(MODULE_CC2420) || defined(MODULE_NATIVENET)) +#define _TC_PAN +#endif +#else /* WITHOUT MODULE_TRANSCEIVER */ +#ifdef MODULE_CC110X extern void _cc110x_get_set_address_handler(char *addr); extern void _cc110x_get_set_channel_handler(char *addr); #endif #endif #ifdef MODULE_TRANSCEIVER -#ifdef MODULE_CC110X_NG -extern void _cc110x_ng_get_set_address_handler(char *addr); -extern void _cc110x_ng_get_set_channel_handler(char *chan); -extern void _cc110x_ng_send_handler(char *pkt); -extern void _cc110x_ng_monitor_handler(char *mode); +#ifdef _TC_ADDR +extern void _transceiver_get_set_address_handler(char *addr); #endif +#ifdef _TC_CHAN +extern void _transceiver_get_set_channel_handler(char *chan); #endif - -#ifdef MODULE_TRANSCEIVER -#ifdef MODULE_CC2420 -extern void _cc2420_get_set_address_handler(char *addr); -extern void _cc2420_get_set_channel_handler(char *chan); -extern void _cc2420_get_set_pan_handler(char *pan); -extern void _cc2420_send_handler(char *pkt); -extern void _cc2420_monitor_handler(char *mode); +#ifdef _TC_SEND +extern void _transceiver_send_handler(char *pkt); #endif +#ifdef _TC_MON +extern void _transceiver_monitor_handler(char *mode); #endif - -#ifdef MODULE_TRANSCEIVER -#ifdef MODULE_NATIVENET -extern void _nativenet_get_set_address_handler(char *addr); -extern void _nativenet_get_set_channel_handler(char *chan); -extern void _nativenet_send_handler(char *pkt); -extern void _nativenet_monitor_handler(char *mode); +#ifdef _TC_PAN +extern void _transceiver_get_set_pan_handler(char *chan); +#endif +#ifdef _TC_IGN +extern void _transceiver_set_ignore_handler(char *addr); #endif #endif @@ -118,41 +123,35 @@ const shell_command_t _shell_command_list[] = { {"cur", "Prints current and average power consumption.", _get_current_handler}, {"rstcur", "Resets coulomb counter.", _reset_current_handler}, #endif -#ifdef MODULE_CC110X + + #ifdef MODULE_TRANSCEIVER - {"addr", "Gets or sets the address for the CC1100 transceiver", _cc1100_get_set_address_handler}, - {"chan", "Gets or sets the channel for the CC1100 transceiver", _cc1100_get_set_channel_handler}, - {"txtsnd", "Sends a text message to a given node via the CC1100 transceiver", _cc1100_send_handler}, -#else +#ifdef _TC_ADDR + {"addr", "Gets or sets the address for the transceiver", _transceiver_get_set_address_handler}, +#endif +#ifdef _TC_CHAN + {"chan", "Gets or sets the channel for the transceiver", _transceiver_get_set_channel_handler}, +#endif +#ifdef _TC_SEND + {"txtsnd", "Sends a text message to a given node via the transceiver", _transceiver_send_handler}, +#endif +#ifdef _TC_PAN + {"pan", "Gets or sets the pan id for the transceiver", _transceiver_get_set_pan_handler}, +#endif +#ifdef _TC_MON + {"monitor", "Enables or disables address checking for the transceiver", _transceiver_monitor_handler}, +#endif +#ifdef _TC_IGN + {"ign", "Ignore the address at the transceiver", _transceiver_set_ignore_handler}, +#endif +#else /* WITHOUT MODULE_TRANSCEIVER */ +#ifdef MODULE_CC110X {"addr", "Gets or sets the address for the CC1100 transceiver", _cc110x_get_set_address_handler}, {"chan", "Gets or sets the channel for the CC1100 transceiver", _cc110x_get_set_channel_handler}, #endif #endif -#ifdef MODULE_TRANSCEIVER -#ifdef MODULE_CC110X_NG - {"addr", "Gets or sets the address for the CC1100 transceiver", _cc110x_ng_get_set_address_handler}, - {"chan", "Gets or sets the channel for the CC1100 transceiver", _cc110x_ng_get_set_channel_handler}, - {"txtsnd", "Sends a text message to a given node via the CC1100 transceiver", _cc110x_ng_send_handler}, - {"monitor", "Enables or disables address checking for the CC1100 transceiver", _cc110x_ng_monitor_handler}, -#endif -#endif -#ifdef MODULE_TRANSCEIVER -#ifdef MODULE_CC2420 - {"addr", "Gets or sets the address for the CC2420 transceiver", _cc2420_get_set_address_handler}, - {"chan", "Gets or sets the channel for the CC2420 transceiver", _cc2420_get_set_channel_handler}, - {"pan", "Gets or sets the pan id for the CC2420 transceiver", _cc2420_get_set_pan_handler}, - {"txtsnd", "Sends a text message to a given node via the C2420 transceiver", _cc2420_send_handler}, - {"monitor", "Enables or disables address checking for the CC2420 transceiver", _cc2420_monitor_handler}, -#endif -#endif -#ifdef MODULE_TRANSCEIVER -#ifdef MODULE_NATIVENET - {"addr", "Gets or sets the address for the native transceiver", _nativenet_get_set_address_handler}, - {"chan", "Gets or sets the channel for the native transceiver", _nativenet_get_set_channel_handler}, - {"txtsnd", "Sends a text message to a given node via the native transceiver", _nativenet_send_handler}, - {"monitor", "Enables or disables address checking for the native transceiver", _nativenet_monitor_handler}, -#endif -#endif + + #ifdef MODULE_MCI {DISK_READ_SECTOR_CMD, "Reads the specified sector of inserted memory card", _read_sector}, {DISK_READ_BYTES_CMD, "Reads the specified bytes from inserted memory card", _read_bytes}, diff --git a/sys/transceiver/transceiver.c b/sys/transceiver/transceiver.c index 0b853df651..29157709f8 100644 --- a/sys/transceiver/transceiver.c +++ b/sys/transceiver/transceiver.c @@ -120,8 +120,8 @@ void receive_at86rf231_packet(radio_packet_t *trans_p); static int8_t send_packet(transceiver_type_t t, void *pkt); static int32_t get_channel(transceiver_type_t t); static int32_t set_channel(transceiver_type_t t, void *channel); -static int16_t get_address(transceiver_type_t t); -static int16_t set_address(transceiver_type_t t, void *address); +static radio_address_t get_address(transceiver_type_t t); +static radio_address_t set_address(transceiver_type_t t, void *address); static int32_t get_pan(transceiver_type_t t); static int32_t set_pan(transceiver_type_t t, void *pan); @@ -283,12 +283,12 @@ void run(void) break; case GET_ADDRESS: - *((int16_t *) cmd->data) = get_address(cmd->transceivers); + *((radio_address_t *) cmd->data) = get_address(cmd->transceivers); msg_reply(&m, &m); break; case SET_ADDRESS: - *((int16_t *) cmd->data) = set_address(cmd->transceivers, cmd->data); + *((radio_address_t *) cmd->data) = set_address(cmd->transceivers, cmd->data); msg_reply(&m, &m); break; @@ -743,6 +743,7 @@ static int32_t get_channel(transceiver_type_t t) #ifdef MODULE_MC1322X case TRANSCEIVER_MC1322X: ///< TODO:implement return maca_get_channel(); + return -1; #endif #ifdef MODULE_NATIVENET case TRANSCEIVER_NATIVE: @@ -827,9 +828,11 @@ static int32_t get_pan(transceiver_type_t t) { * * @param t The transceiver device * - * @return The configured address of the device, -1 on error + * @return The configured address of the device + * + * TODO: define error behavior */ -static int16_t get_address(transceiver_type_t t) +static radio_address_t get_address(transceiver_type_t t) { switch(t) { case TRANSCEIVER_CC1100: @@ -838,7 +841,7 @@ static int16_t get_address(transceiver_type_t t) #elif MODULE_CC110X return cc1100_get_address(); #else - return -1; + return 0; /* XXX see TODO above */ #endif #ifdef MODULE_CC2420 case TRANSCEIVER_CC2420: @@ -857,7 +860,7 @@ static int16_t get_address(transceiver_type_t t) return at86rf231_get_address(); #endif default: - return -1; + return 0; /* XXX see TODO above */ } } @@ -868,8 +871,10 @@ static int16_t get_address(transceiver_type_t t) * @param address Generic pointer to the address to set * * @return The new radio address of the device + * + * TODO: define error behavior */ -static int16_t set_address(transceiver_type_t t, void *address) +static radio_address_t set_address(transceiver_type_t t, void *address) { radio_address_t addr = *((radio_address_t *)address); @@ -880,7 +885,7 @@ static int16_t set_address(transceiver_type_t t, void *address) #elif MODULE_CC110X return cc1100_set_address(addr); #else - return -1; + return 0; /* XXX see TODO above */ #endif #ifdef MODULE_CC2420 case TRANSCEIVER_CC2420: @@ -899,7 +904,7 @@ static int16_t set_address(transceiver_type_t t, void *address) return at86rf231_set_address(addr); #endif default: - return -1; + return 0; /* XXX see TODO above */ } }