Made send intervals configurable when sending a new file

This commit is contained in:
adamdunkels 2007-04-02 09:51:45 +00:00
parent 0f17706ef3
commit a26906f478
4 changed files with 24 additions and 21 deletions

View file

@ -33,7 +33,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: rudolph0.c,v 1.3 2007/03/31 18:31:28 adamdunkels Exp $
* $Id: rudolph0.c,v 1.4 2007/04/02 09:51:45 adamdunkels Exp $
*/
/**
@ -48,7 +48,6 @@
#include "net/rime.h"
#include "net/rime/rudolph0.h"
#define SENDING_TIME CLOCK_SECOND / 2
#define STEADY_TIME CLOCK_SECOND * 2
enum {
@ -99,7 +98,7 @@ send_nack(struct rudolph0_conn *c)
hdr->chunk = c->current.h.chunk;
PRINTF("Sending nack for %d:%d\n", hdr->version, hdr->chunk);
uabc_send(&c->nackc, CLOCK_SECOND / 4);
uabc_send(&c->nackc, c->send_interval / 2);
}
/*---------------------------------------------------------------------------*/
static void
@ -175,7 +174,7 @@ recv_nack(struct uabc_conn *uabc)
c->current.h.chunk = 0;
}
read_new_datapacket(c);
sabc_set_timer(&c->c, SENDING_TIME);
sabc_set_timer(&c->c, c->send_interval);
}
}
/*---------------------------------------------------------------------------*/
@ -201,7 +200,7 @@ rudolph0_close(struct rudolph0_conn *c)
}
/*---------------------------------------------------------------------------*/
void
rudolph0_send(struct rudolph0_conn *c)
rudolph0_send(struct rudolph0_conn *c, clock_time_t send_interval)
{
c->state = STATE_SENDER;
c->current.h.version++;
@ -209,7 +208,8 @@ rudolph0_send(struct rudolph0_conn *c)
c->current.h.type = TYPE_DATA;
read_new_datapacket(c);
rimebuf_reference(&c->current, sizeof(struct rudolph0_datapacket));
sabc_send_stubborn(&c->c, SENDING_TIME);
c->send_interval = send_interval;
sabc_send_stubborn(&c->c, c->send_interval);
}
/*---------------------------------------------------------------------------*/
void

View file

@ -47,7 +47,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: rudolph0.h,v 1.2 2007/03/31 18:31:28 adamdunkels Exp $
* $Id: rudolph0.h,v 1.3 2007/04/02 09:51:45 adamdunkels Exp $
*/
/**
@ -98,6 +98,7 @@ struct rudolph0_conn {
struct sabc_conn c;
struct uabc_conn nackc;
const struct rudolph0_callbacks *cb;
clock_time_t send_interval;
u8_t state;
struct rudolph0_datapacket current;
};
@ -105,7 +106,7 @@ struct rudolph0_conn {
void rudolph0_open(struct rudolph0_conn *c, u16_t channel,
const struct rudolph0_callbacks *cb);
void rudolph0_close(struct rudolph0_conn *c);
void rudolph0_send(struct rudolph0_conn *c);
void rudolph0_send(struct rudolph0_conn *c, clock_time_t interval);
void rudolph0_stop(struct rudolph0_conn *c);
void rudolph0_set_version(struct rudolph0_conn *c, int version);

View file

@ -33,7 +33,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: rudolph1.c,v 1.5 2007/03/31 18:31:28 adamdunkels Exp $
* $Id: rudolph1.c,v 1.6 2007/04/02 09:51:45 adamdunkels Exp $
*/
/**
@ -50,9 +50,8 @@
#include "net/rime/rudolph1.h"
#include "cfs/cfs.h"
#define DATA_INTERVAL CLOCK_SECOND * 2
#define TRICKLE_INTERVAL TRICKLE_SECOND
#define NACK_TIMEOUT CLOCK_SECOND
#define NACK_TIMEOUT CLOCK_SECOND / 4
struct rudolph1_hdr {
u8_t type;
@ -151,12 +150,12 @@ static void
handle_data(struct rudolph1_conn *c, struct rudolph1_datapacket *p)
{
if(LT(c->version, p->h.version)) {
PRINTF("rudolph1 new version %d\n", p->h.version);
PRINTF("rudolph1 new version %d, chunk %d\n", p->h.version, p->h.chunk);
c->version = p->h.version;
c->chunk = 1; /* Next chunk is 1. */
if(p->h.chunk != 0) {
send_nack(c);
} else {
c->chunk = 1; /* Next chunk is 1. */
write_data(c, 0, p->data, p->datalen);
}
/* }*/
@ -199,14 +198,15 @@ recv_uabc(struct uabc_conn *uabc)
c->nacks++;
if(p->h.type == TYPE_NACK) {
PRINTF("Got NACK for %d:%d\n", p->h.version, p->h.chunk);
if(p->h.version == c->version) {
if(p->h.chunk < c->chunk) {
format_data(c, p->h.chunk);
uabc_send(&c->uabc, NACK_TIMEOUT);
uabc_send(&c->uabc, c->send_interval / 2);
}
} else if(LT(p->h.version, c->version)) {
format_data(c, 0);
uabc_send(&c->uabc, NACK_TIMEOUT);
uabc_send(&c->uabc, c->send_interval / 2);
}
} else if(p->h.type == TYPE_DATA) {
handle_data(c, p);
@ -223,10 +223,10 @@ send_next_packet(void *ptr)
len = format_data(c, c->chunk);
trickle_send(&c->trickle, c->trickle_interval);
if(len == RUDOLPH1_DATASIZE) {
ctimer_set(&c->t, DATA_INTERVAL, send_next_packet, c);
ctimer_set(&c->t, c->send_interval, send_next_packet, c);
}
} else {
ctimer_set(&c->t, DATA_INTERVAL, send_next_packet, c);
ctimer_set(&c->t, c->send_interval, send_next_packet, c);
}
c->nacks = 0;
}
@ -252,14 +252,15 @@ rudolph1_close(struct rudolph1_conn *c)
}
/*---------------------------------------------------------------------------*/
void
rudolph1_send(struct rudolph1_conn *c)
rudolph1_send(struct rudolph1_conn *c, clock_time_t send_interval)
{
c->version++;
c->chunk = 0;
c->trickle_interval = TRICKLE_INTERVAL;
format_data(c, 0);
trickle_send(&c->trickle, c->trickle_interval);
ctimer_set(&c->t, DATA_INTERVAL, send_next_packet, c);
c->send_interval = send_interval;
ctimer_set(&c->t, send_interval, send_next_packet, c);
}
/*---------------------------------------------------------------------------*/
void

View file

@ -47,7 +47,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: rudolph1.h,v 1.2 2007/03/31 18:31:28 adamdunkels Exp $
* $Id: rudolph1.h,v 1.3 2007/04/02 09:51:45 adamdunkels Exp $
*/
/**
@ -85,6 +85,7 @@ struct rudolph1_conn {
struct uabc_conn uabc;
const struct rudolph1_callbacks *cb;
struct ctimer t;
clock_time_t send_interval;
u16_t chunk;
u8_t version;
u8_t trickle_interval;
@ -94,7 +95,7 @@ struct rudolph1_conn {
void rudolph1_open(struct rudolph1_conn *c, u16_t channel,
const struct rudolph1_callbacks *cb);
void rudolph1_close(struct rudolph1_conn *c);
void rudolph1_send(struct rudolph1_conn *c);
void rudolph1_send(struct rudolph1_conn *c, clock_time_t send_interval);
void rudolph1_stop(struct rudolph1_conn *c);
#endif /* __RUDOLPH1_H__ */