1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-25 06:23:53 +01:00

Ping entfernt, nur noch broadcast moeglich

This commit is contained in:
Stephan Arndt 2013-01-28 12:39:44 +01:00
parent 6d9416e327
commit 525bc3f64a
5 changed files with 9 additions and 307 deletions

View File

@ -1,5 +1,5 @@
SubDir TOP projects test_ping ;
Module test_ping : main.c pingpong.c : shell shell_commands ps uart0 posix_io auto_init vtimer swtimer 6lowpan cc110x transceiver ;
Module test_ping : main.c pingpong.c : shell shell_commands ps uart0 posix_io auto_init vtimer cc110x transceiver ;
UseModule test_ping ;

View File

@ -43,9 +43,6 @@ const shell_command_t shell_commands[] =
"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 },
{ NULL, NULL, NULL }
};
@ -105,8 +102,6 @@ void help(char* cmdname) {
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)) {
@ -119,29 +114,10 @@ void help(char* cmdname) {
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'");
puts("Recognized command is 'init'");
}
}
@ -176,34 +152,6 @@ void broadcast(char* arg) {
}
// see header for documentation
void ping(char* arg) {
uint16_t addr;
if (!isinit) {
// don't try to send without proper init
puts("[ERROR] Cannot send while radio is not initialized!");
return;
}
int res = sscanf(arg, "ping %hu", &addr);
if (res > 0) {
if (addr < MAX_ADDR) {
printf("Ready to send to address %d\n", addr);
pingpong(addr, 5);
} else {
printf("ERROR: Please give an address which is in range %d to %d.",
MIN_ADDR, MAX_ADDR);
}
} else {
puts("ERROR: Please give an address which you wish to ping.");
puts("For more information on how to use ping, type 'help ping'.");
}
}
// see header for documentation
void set_radio_address(uint8_t address) {
uint16_t addr = (uint16_t) address;
@ -238,14 +186,6 @@ void set_radio_channel(uint8_t channel) {
msg_send_receive(&mesg, &mesg, transceiver_pid);
}
// see header for documentation
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
void radio(void) {
msg_t m;
@ -269,11 +209,7 @@ void radio(void) {
printf("Type: %d, ", ping_pkt->type);
printf("Seq#: %d\n", ping_pkt->seq_nr);
if (ping_pkt->type == PING) {
ping_incoming((uint8_t) p->src);
} else if (ping_pkt->type == PING_ACK) {
ack_incoming();
} else if (ping_pkt->type == PING_BCST) {
if (ping_pkt->type == PING_BCST) {
broadcast_incoming();
}

View File

@ -58,14 +58,6 @@ void init(char * arg);
*/
void broadcast(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(char * arg);
/**
* @brief Returns the radio address of this device.
*
@ -90,18 +82,6 @@ void set_radio_address(uint8_t addr);
*/
void set_radio_channel(uint8_t chan);
/**
* @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.
* If the node was not pinging at the time of the method-call, this method does
* nothing.
*
* @param arg unused
*/
void stop(char * arg);
/**
* @brief The thread for the processing of received radio-packets.
*/

View File

@ -7,19 +7,10 @@
#include <vtimer.h>
#include <thread.h>
#include <msg.h>
#include <swtimer.h>
//net stuff
#include <transceiver.h>
char stack_stop[XS_STACK];
static uint64_t start = 0;
static uint64_t end = 0;
static float rtt = 0;
static bool cont_ping = false;
static uint16_t time = 0;
static int wait_pid = 0;
static uint16_t sequence = 0;
radio_packet_t p;
@ -27,149 +18,28 @@ ping_packet_t ping_packet;
transceiver_command_t tcmd;
msg_t mesg;
// see header for documentation
void stop_after_time() {
vtimer_usleep(time * SECOND);
stop_now();
}
// see header for documentation
void stop_now() {
puts("stopping now");
cont_ping = false;
}
// see header for documentation
void pingpong(uint8_t addr, uint16_t duration) {
cont_ping = true;
time = duration;
if (time) {
//A time has been given after which pings should not be sent anymore
thread_create(stack_stop, XS_STACK, PRIORITY_MAIN - 2, CREATE_STACKTEST,
stop_after_time, "showstopper");
}
while (cont_ping) {
start = swtimer_now();
wait_pid = thread_getpid();
send_ping(addr);
wait_pong();
//savestats();
}
//We're done, print endstats
//printendstats();
}
// see header for documentation
void wait_pong() {
//Either sleep 2 seconds or get waken up in between
vtimer_usleep(2 * SECOND);
calc_rtt();
if (rtt > 2000) {
//this means that the pong to this ping wasn't received
print_failure();
} else {
print_success();
}
}
// see header for documentation
void broadcast_without_ack(uint16_t duration) {
cont_ping = true;
time = duration;
uint8_t counter = 0;
uint16_t seconds = 10;
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,
stop_after_time, "showstopper");
if (duration > 0) {
seconds = duration;
}
while (cont_ping) {
puts("Setting up packet");
//TODO replace swtimer with vtimer
start = swtimer_now();
while(counter < seconds){
puts("Setting up packet");
send_broadcast();
vtimer_usleep(1 * SECOND);
}
}
// see header for documentation
void ping_incoming(uint8_t src) {
puts("Ping in, sending ack out");
send_ack(src);
}
// see header for documentation
void ack_incoming() {
thread_wakeup(wait_pid);
puts("Ping got acked");
}
// see header for documentation
void broadcast_incoming() {
puts("got some broadcasted stuff");
}
// see header for documentation
void print_success() {
printf("%s%f%s\n", "time=", rtt, "ms");
}
// see header for documentation
void print_failure() {
puts("Time for ping exceeded");
}
// see header for documentation
void send_ping(uint8_t addr) {
mesg.type = SND_PKT;
mesg.content.ptr = (char*) &tcmd;
tcmd.transceivers = TRANSCEIVER_CC1100;
tcmd.data = &p;
p.length = sizeof(ping_packet_t);
p.dst = addr;
puts("creating packet..");
sequence++;
ping_packet.seq_nr = sequence;
ping_packet.type = PING;
puts("sending ping..");
printf("pingpacket address: %p", &ping_packet);
printf("pingpacket seqnr: %d", ping_packet.seq_nr);
printf("pingpacket type: %d\n", ping_packet.type);
thread_print_all();
p.data = (uint8_t *) &ping_packet;
msg_send(&mesg, transceiver_pid, 1);
puts("sent");
}
// see header for documentation
void send_ack(uint8_t addr) {
mesg.type = SND_PKT;
mesg.content.ptr = (char*) &tcmd;
tcmd.transceivers = TRANSCEIVER_CC1100;
tcmd.data = &p;
p.length = sizeof(ping_packet_t);
p.dst = addr;
puts("creating packet..");
sequence++;
ping_packet.seq_nr = sequence;
ping_packet.type = PING_ACK;
puts("sending ack..");
p.data = (uint8_t *) &ping_packet;
msg_send(&mesg, transceiver_pid, 1);
puts("sent");
}
// see header for documentation
void send_broadcast() {
puts("Preparing broadcast ping");
@ -191,9 +61,3 @@ void send_broadcast() {
msg_send(&mesg, transceiver_pid, 1);
puts("sent");
}
// see header for documentation
void calc_rtt() {
end = swtimer_now();
rtt = ((float) end - (float) start) / 1000;
}

View File

@ -3,7 +3,6 @@
#include <stdint.h>
#define XS_STACK (400)
#define SECOND (1000*1000)
/**
@ -27,23 +26,6 @@ typedef struct __attribute__((packed)) {
uint8_t type ;
} ping_packet_t;
/**
* @brief The method that sends a ping to an address addr for duration seconds.
*
* This method sends a ping to the given address addr for duration seconds.
*
* @param addr A radio address to send pings to.
* @param duration A duration in seconds.
*/
void pingpong(uint8_t addr, uint16_t duration);
/**
* @brief Waits for an acknowledgment of a previously sent ping.
*
* This method is an internal method and should not be called from the outside.
*/
void wait_pong();
/**
* @brief Sends a broadcast for duration seconds.
*
@ -54,74 +36,14 @@ void wait_pong();
*/
void broadcast_without_ack(uint16_t duration);
/**
* @brief Handles incoming PING messages.
*
* @param src the source-address from which the pingmessage originated from.
*/
void ping_incoming(uint8_t src);
/**
* @brief Handles incoming ACK messages.
*/
void ack_incoming();
/**
* @brief Handles incoming broadcast messages.
*/
void broadcast_incoming();
/**
* @brief The internal method for sending a pingmessage to address addr.
* @param addr The address to send a pingmessage to.
*/
void send_ping(uint8_t addr);
/**
* @brief The internal method for sending an acknowledgment of a ping to address
* addr.
*
* @param addr The address to send an acknowledgment to.
*/
void send_ack(uint8_t addr);
/**
* @brief The internal method for sending a broadcast message.
*/
void send_broadcast();
/**
* @brief The internal method to calculate the Round-Trip-Time for a ping.
*/
void calc_rtt(void);
/**
* @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_now(void);
/**
* @brief The internal thread that stops this node from pinging a target after a
* specified time.
*/
void stop_after_time(void);
/**
* @brief Prints a success message when a ping was sent and an ACK for it was
* returned.
*
* This method pings the Round-Trip-Time for a pingmessage to which an ACK was
* received.
*/
void print_success();
/**
* @brief Prints a failure message if a ping exceeds the timelimit for an ACK
* to be received.
*/
void print_failure();
#endif /* PING_H */