diff --git a/projects/test_ping/Jamfile b/projects/test_ping/Jamfile index ce99c97eee..39a205aa69 100644 --- a/projects/test_ping/Jamfile +++ b/projects/test_ping/Jamfile @@ -1,5 +1,5 @@ SubDir TOP projects test_ping ; -Module test_ping : main.c : shell shell_commands ps uart0 posix_io auto_init vtimer cc110x ; +Module test_ping : main.c : shell shell_commands ps uart0 posix_io auto_init vtimer 6lowpan cc110x transceiver ; UseModule test_ping ; diff --git a/projects/test_ping/main.c b/projects/test_ping/main.c index a3d5eac1c8..2039089d4e 100644 --- a/projects/test_ping/main.c +++ b/projects/test_ping/main.c @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -7,60 +9,161 @@ #include #include #include +#include -// Prototypes -void help(char * arg); -void init(char * arg); -void ping(char * arg); -void stop(char * arg); +#define STACKSIZE KERNEL_CONF_STACKSIZE_DEFAULT + +char stack[STACKSIZE]; // Shell commands for this application const shell_command_t shell_commands[] = -{ { "help", "Prints the help", help }, - { "init", "Initializes this node with an address and a channel.", init }, - { "ping", "Makes this node a pinging node", ping }, - { "stop", "Stops the current node's pings and prints a summary", stop }, - { NULL, NULL, NULL } -}; + { { "help", "Prints the help", help }, + { "init", + "Initializes this node with an address and a channel.", + init }, + { "ping", "Makes this node a pinging node", ping }, + { "stop", "Stops the current node's pings and prints a summary", + stop }, + { NULL, NULL, NULL } + }; -/** - * Initializes this node with a given radio address and on a given channel or - * on a default channel, if no channel is given. A radio address must be given - * in any case. - */ +// pid of ongoing ping thread, 0 if not set +int pid_pingthread = 0; + +// see header for documentation void init(char* arg) { -//TODO implement + transceiver_command_t tcmd; + msg_t m; + uint16_t addr = 0; + uint16_t chan = 10; + + printf("transceiver pid is %d.\n", transceiver_pid); + + int res = sscanf(arg, "init %hu %hu", &addr, &chan); + if (res == 1) { + puts("Setting address, keeping default channel"); + + if (addr >= MIN_ADDR && addr <= MAX_ADDR + && chan >= MIN_CHAN && chan <= MAX_CHAN) { + //addr. given, channel should be default, which is 10 for us + //check for validity in any case, just to be sure + + + puts("Initializing 6lowpan.."); + sixlowpan_init(TRANSCEIVER_CC1100,addr,0); + puts("Address set, setting channel"); + + tcmd.data = &chan; + m.type = SET_CHANNEL; + m.content.ptr = (void*) &tcmd; + + puts("waiting for transceiver.."); + msg_send_receive(&m, &m, transceiver_pid); + puts("Channel set."); + + } else { + printf("ERROR: The address for the node has to be in %d to %d.\n", + MIN_ADDR, MAX_ADDR); + } + + } else if (res == 2) { + puts("Setting address and channel"); + + if (addr >= MIN_ADDR && addr <= MAX_ADDR + && chan >= MIN_CHAN && chan <= MAX_CHAN) { + //addr. & channel are given, check validity + + puts("Initializing 6lowpan.."); + sixlowpan_init(TRANSCEIVER_CC1100,addr,0); + puts("address set, setting channel"); + + tcmd.data = &chan; + m.type = SET_CHANNEL; + m.content.ptr = (void*) &tcmd; + + puts("waiting for transceiver.."); + msg_send_receive(&m, &m, transceiver_pid); + puts("channel set"); + } else { + printf("ERROR: The address for the node has to be in %d to %d.\n", + MIN_ADDR, MAX_ADDR); + printf("ERROR: The channel for the node has to be in %d to %d.\n", + MIN_CHAN, MAX_CHAN); + } + //addr and channel given + } else { + //no correct argument given, but radio address is mandatory + puts("Usage: init [radioaddr] (radiochannel)"); + puts("Use 'help init' for more information on this command."); + } } -/** - * Prints the shellcommands that are usable in this application for reference. - */ -void help(char* unused) { - printf("These are the usable commands:\n"); - printf("\thelp (commandname)\n"); - printf("\tinit [address] (channel)\n"); - printf("\tping [address] (time)\n"); - printf("\tstop\n"); - printf("\n"); - printf("[] = mandatory, () = optional\n"); +// see header for documentation +void help(char* cmdname) { + char *command = cmdname; + while (*command != '\0' && *command++ != ' ') + ; //Skip the command by going till first space + + if (strlen(cmdname) == 4) { + puts("These are the usable commands:"); + puts("\thelp (commandname)"); + puts("\tinit [address] (channel)"); + puts("\tping [address] (time)"); + puts("\tstop"); + puts(""); + puts("[] = mandatory, () = optional"); + } else if (!strcasecmp("init", command)) { + puts("init: Initializes a node for radio communication."); + puts(" +"); + puts( + " +---[address]: The radio-address that this node should assume (range: 0 to 255)"); + puts(" + This argument is mandatory."); + puts(" +"); + puts(" +---(channel): The radio-channel that this node should use"); + puts(" This argument is optional."); + puts(" Uses a default channel if not given."); + } else if (!strcasecmp("ping", command)) { + puts( + "ping: Sends ping-messages to another node and records statistics on the number"); + puts( + " + of sent messages/received messages as well as the RTT of those pings."); + puts(" +"); + puts( + " +---[address]: The radio-address that this node should send its pings to)"); + puts(" + This argument is mandatory."); + puts(" +"); + puts( + " +---(time) : The duration (in seconds) that these ping messages should "); + puts(" be sent over"); + puts(" This argument is optional."); + puts(" Sends infinite pings when no time is given."); + } else if (!strcasecmp("stop", command)) { + puts("stop: Stops any ongoing pings this node sends out."); + puts( + " If this node is currently not sending any pings, this command does nothing."); + } else { + puts("The command given was not recognized. You gave:"); + puts(command); + puts("Recognized commands are 'init','ping' and 'stop'"); + } } -/** - * Sends out pings from this node to another node in a continuous manner, until - * the stop command is used. - */ -void ping(char* unused) { -//TODO implement +// see header for docs +void ping() { + //TODO implement } -/** - * Stops any current pinging-action by this node and prints a summary of how - * many pings got returned. - * If the node was not pinging at the time of the method-call, this method does - * nothing. - */ void stop(char* unused) { -//TODO implement + //TODO implement + if (pid_pingthread) { + } +} + +void hellothread(){ + while(true){ + puts("Hello!"); + vtimer_usleep(1000*2000); //2secs + } } /** @@ -71,6 +174,8 @@ int main(void) { puts("Ping Test Application\n"); puts("For commands type 'help'!\n"); + thread_create(stack, STACKSIZE, PRIORITY_MAIN -3,8, hellothread,"hello"); + posix_open(uart0_handler_pid, 0); shell_t shell; @@ -80,3 +185,4 @@ int main(void) { return 0; } + diff --git a/projects/test_ping/main.h b/projects/test_ping/main.h new file mode 100644 index 0000000000..6128b97e16 --- /dev/null +++ b/projects/test_ping/main.h @@ -0,0 +1,45 @@ +#ifndef PING_TEST_H + +#define PING_TEST_H + +#define MIN_ADDR 1 +#define MIN_CHAN MIN_ADDR +#define MAX_CHAN 14 +#define MAX_ADDR 255 + +/** + * @brief Shows a helping text. + * @param command the command name for which the help should be showed. + */ +void help(char * commandname); + +/** + * @brief Initializes a node for radio communication + * + * Initializes this node with a given radio address and on a given channel or + * on a default channel, if no channel is given. A radio address must be given + * in any case. + * + * @param arg + */ +void init(char * arg); + +/** + * @brief Pings another node. + * + * Sends out pings from this node to another node in a continuous manner, until + * the stop command is used. + */ +void ping(); + +/** + * Stops any current pinging-action by this node and prints a summary of how + * many pings got returned. + * If the node was not pinging at the time of the method-call, this method does + * nothing. + * + * @param arg + */ +void stop(char * arg); + +#endif /* PING_TEST_H */