diff --git a/projects/test_ping/main.c b/projects/test_ping/main.c index bf9e8c6a0e..a2eab0b0cd 100644 --- a/projects/test_ping/main.c +++ b/projects/test_ping/main.c @@ -42,9 +42,10 @@ const shell_command_t shell_commands[] = { "init", "Initializes this node with an address and a channel.", init }, + { "broadcast", "Puts this node into broadcast mode", broadcast }, { "ping", "Makes this node a pinging node", ping }, { "stop", "Stops the current node's pings and prints a summary", - stop_pings }, + stop }, { NULL, NULL, NULL } }; @@ -144,6 +145,37 @@ void help(char* cmdname) { } } +// see header for documentation +void broadcast(char* arg) { + uint16_t duration; + + if (!isinit) { + // don't try to send without proper init + puts("[ERROR] Cannot broadcast while radio is not initialized!"); + return; + } + + int res = sscanf(arg, "broadcast %hu", &duration); + + if (res > 0) { + if (duration < MAX_ADDR) { + printf("Ready to broadcast for a duration of %d seconds\n", + duration); + + broadcast_without_ack(duration); + + } else { + printf("ERROR: Please give a duration which is in range %d to %d.", + MIN_DURATION, MAX_DURATION); + } + } else { + puts("ERROR: Please give a duration for which you wish to broadcast."); + puts( + "For more information on how to use broadcast, type 'help broadcast'."); + } + +} + // see header for documentation void ping(char* arg) { uint16_t addr; @@ -207,8 +239,11 @@ void set_radio_channel(uint8_t channel) { } // see header for documentation -void stop_pings(char* unused) { - stop(); +void stop(char* unused) { + //TODO doesn't work, since broadcasting runs in the same thread, either del + //or make the whole thing threaded + puts("calling stop_now"); + stop_now(); } // see header for documentation diff --git a/projects/test_ping/main.h b/projects/test_ping/main.h index 70830b474c..aa0d2f2c35 100644 --- a/projects/test_ping/main.h +++ b/projects/test_ping/main.h @@ -17,6 +17,13 @@ #define MIN_CHAN MIN_CHANNR #define MAX_CHAN MAX_CHANNR +/** + * Maximum and minimum duration times + * TODO change min duration to 0 once stopping works as intended + */ +#define MIN_DURATION 1 +#define MAX_DURATION UINT16_MAX + /** * Receive- and send-buffer size */ @@ -40,6 +47,17 @@ void help(char * commandname); */ void init(char * arg); +/** + * @brief broadcasts for a specified duration + * + * Broadcasts a pingmessage from this node in a continuous manner until the + * duration (in seconds) is over or the stop command is used. + * If the duration is set to 0, it broadcasts endlessly until the stop command + * is used. + * @param arg + */ +void broadcast(char* arg); + /** * @brief Pings another node. * @@ -73,7 +91,7 @@ void set_radio_address(uint8_t addr); void set_radio_channel(uint8_t chan); /** - * @brief Stops this node from pinging. + * @brief Stops this node from sending broadcasts or pings. * * Stops any current pinging-action by this node and prints a summary of how * many pings got returned. @@ -82,7 +100,7 @@ void set_radio_channel(uint8_t chan); * * @param arg unused */ -void stop_pings(char * arg); +void stop(char * arg); /** * @brief The thread for the processing of received radio-packets. diff --git a/projects/test_ping/pingpong.c b/projects/test_ping/pingpong.c index 610616dbfa..5060e6ba58 100644 --- a/projects/test_ping/pingpong.c +++ b/projects/test_ping/pingpong.c @@ -30,11 +30,12 @@ msg_t mesg; // see header for documentation void stop_after_time() { vtimer_usleep(time * SECOND); - stop(); + stop_now(); } // see header for documentation -void stop() { +void stop_now() { + puts("stopping now"); cont_ping = false; } @@ -75,8 +76,10 @@ void wait_pong() { // see header for documentation void broadcast_without_ack(uint16_t duration) { + cont_ping = true; time = duration; + puts("Setting up broadcast"); if (time) { //A time has been given after which pings should not be sent anymore thread_create(stack_stop, XS_STACK, PRIORITY_MAIN - 2, 0, @@ -84,9 +87,11 @@ void broadcast_without_ack(uint16_t duration) { } while (cont_ping) { + puts("Setting up packet"); + //TODO replace swtimer with vtimer start = swtimer_now(); send_broadcast(); - vtimer_usleep(500 * 1000); + vtimer_usleep(1 * SECOND); } } @@ -167,6 +172,7 @@ void send_ack(uint8_t addr) { // see header for documentation void send_broadcast() { + puts("Preparing broadcast ping"); mesg.type = SND_PKT; mesg.content.ptr = (char*) &tcmd; diff --git a/projects/test_ping/pingpong.h b/projects/test_ping/pingpong.h index e388c2b894..267164ad7d 100644 --- a/projects/test_ping/pingpong.h +++ b/projects/test_ping/pingpong.h @@ -96,12 +96,12 @@ void send_broadcast(); void calc_rtt(void); /** - * @brief The internal method to stop this node from pinging a target. + * @brief The internal method to stop this node from pinging or broadcasting. * * This method should be used for example if a ping was given without a * duration, so without manually stopping the node it would send endlessly. */ -void stop(void); +void stop_now(void); /** * @brief The internal thread that stops this node from pinging a target after a