1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00
RIOT/projects/test_ping/pingpong.c

77 lines
1.5 KiB
C
Raw Normal View History

//include thy header!
#include <pingpong.h>
//standard stuff
#include <stdio.h>
#include <string.h>
#include <vtimer.h>
#include <thread.h>
#include <msg.h>
//net stuff
#include <transceiver.h>
2013-02-13 14:56:46 +01:00
//debug stuff
//#define ENABLE_DEBUG
#ifdef ENABLE_DEBUG
#include <ps.h>
#endif
static uint16_t sequence = 0;
radio_packet_t p;
ping_packet_t ping_packet;
transceiver_command_t tcmd;
msg_t mesg;
// see header for documentation
void broadcast_without_ack(uint16_t duration) {
uint8_t counter = 0;
uint16_t seconds = 10;
2013-01-08 15:24:57 +01:00
puts("Setting up broadcast");
if (duration > 0) {
seconds = duration;
}
while(counter < seconds){
puts("Setting up packet");
2013-01-28 13:30:47 +01:00
counter = counter + 1;
send_broadcast();
2013-02-13 14:56:46 +01:00
#ifdef ENABLE_DEBUG
thread_print_all();
vtimer_print_short_queue();
vtimer_print_long_queue();
#endif
2013-01-08 15:24:57 +01:00
vtimer_usleep(1 * SECOND);
}
2013-01-30 18:56:23 +01:00
puts("stopping now");
}
// see header for documentation
void broadcast_incoming() {
puts("got some broadcasted stuff");
}
// see header for documentation
void send_broadcast() {
2013-01-08 15:24:57 +01:00
puts("Preparing broadcast ping");
mesg.type = SND_PKT;
mesg.content.ptr = (char*) &tcmd;
tcmd.transceivers = TRANSCEIVER_CC1100;
tcmd.data = &p;
p.length = sizeof(ping_packet_t);
p.dst = 0;
puts("creating packet..");
sequence++;
ping_packet.seq_nr = sequence;
ping_packet.type = PING_BCST;
puts("sending broadcast..");
p.data = (uint8_t *) &ping_packet;
msg_send(&mesg, transceiver_pid, 1);
puts("sent");
}