Removed the use of CFS. Instead, provide callbacks for the using application to fill in data.
This commit is contained in:
parent
62430052ff
commit
dd276a9c8a
6 changed files with 203 additions and 108 deletions
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: rudolph0.c,v 1.2 2007/03/21 23:18:23 adamdunkels Exp $
|
||||
* $Id: rudolph0.c,v 1.3 2007/03/22 23:54:40 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -40,7 +40,6 @@
|
|||
|
||||
#include "net/rime.h"
|
||||
#include "rudolph0.h"
|
||||
#include "cfs/cfs.h"
|
||||
|
||||
#include <stddef.h> /* for offsetof */
|
||||
|
||||
|
@ -71,9 +70,12 @@ enum {
|
|||
static void
|
||||
read_new_datapacket(struct rudolph0_conn *c)
|
||||
{
|
||||
int len;
|
||||
int len = 0;
|
||||
|
||||
len = cfs_read(c->cfs_fd, c->current.data, RUDOLPH0_DATASIZE);
|
||||
if(c->cb->read_chunk) {
|
||||
len = c->cb->read_chunk(c, c->current.h.chunk * RUDOLPH0_DATASIZE,
|
||||
c->current.data, RUDOLPH0_DATASIZE);
|
||||
}
|
||||
c->current.datalen = len;
|
||||
|
||||
PRINTF("read_new_datapacket len %d\n", len);
|
||||
|
@ -124,36 +126,30 @@ recv(struct sabc_conn *sabc)
|
|||
if(p->h.type == TYPE_DATA) {
|
||||
if(c->current.h.version != p->h.version) {
|
||||
PRINTF("rudolph0 new version %d\n", p->h.version);
|
||||
if(c->cfs_fd != -1) {
|
||||
cfs_close(c->cfs_fd);
|
||||
}
|
||||
c->cfs_fd = c->cb->new_file(c);
|
||||
c->current.h.version = p->h.version;
|
||||
c->current.h.chunk = 0;
|
||||
if(c->cfs_fd != -1) {
|
||||
if(p->h.chunk != 0) {
|
||||
send_nack(c);
|
||||
c->cb->write_chunk(c, 0, RUDOLPH0_FLAG_NEWFILE, p->data, 0);
|
||||
if(p->h.chunk != 0) {
|
||||
send_nack(c);
|
||||
} else {
|
||||
cfs_write(c->cfs_fd, p->data, p->datalen);
|
||||
c->cb->write_chunk(c, 0, RUDOLPH0_FLAG_NONE, p->data, p->datalen);
|
||||
c->current.h.chunk++;
|
||||
}
|
||||
}
|
||||
} else if(p->h.version == c->current.h.version) {
|
||||
if(c->cfs_fd != -1) {
|
||||
if(p->h.chunk == c->current.h.chunk) {
|
||||
PRINTF("received chunk %d\n", p->h.chunk);
|
||||
cfs_write(c->cfs_fd, p->data, p->datalen);
|
||||
c->current.h.chunk++;
|
||||
if(p->datalen < RUDOLPH0_DATASIZE) {
|
||||
cfs_close(c->cfs_fd);
|
||||
c->cfs_fd = -1;
|
||||
c->cb->received_file(c);
|
||||
}
|
||||
|
||||
} else if(p->h.chunk > c->current.h.chunk) {
|
||||
PRINTF("received chunk %d > %d, sending NACK\n", p->h.chunk, c->current.h.chunk);
|
||||
send_nack(c);
|
||||
if(p->h.chunk == c->current.h.chunk) {
|
||||
PRINTF("received chunk %d\n", p->h.chunk);
|
||||
if(p->datalen < RUDOLPH0_DATASIZE) {
|
||||
c->cb->write_chunk(c, c->current.h.chunk * RUDOLPH0_DATASIZE,
|
||||
RUDOLPH0_FLAG_LASTCHUNK, p->data, p->datalen);
|
||||
} else {
|
||||
c->cb->write_chunk(c, c->current.h.chunk * RUDOLPH0_DATASIZE,
|
||||
RUDOLPH0_FLAG_NONE, p->data, p->datalen);
|
||||
}
|
||||
c->current.h.chunk++;
|
||||
|
||||
} else if(p->h.chunk > c->current.h.chunk) {
|
||||
PRINTF("received chunk %d > %d, sending NACK\n", p->h.chunk, c->current.h.chunk);
|
||||
send_nack(c);
|
||||
}
|
||||
} else { /* p->h.version < c->current.h.version */
|
||||
/* Ignore packets with old version */
|
||||
|
@ -173,11 +169,9 @@ recv_nack(struct uabc_conn *uabc)
|
|||
if(p->h.version == c->current.h.version) {
|
||||
PRINTF("Reseting chunk to %d\n", p->h.chunk);
|
||||
c->current.h.chunk = p->h.chunk;
|
||||
cfs_seek(c->cfs_fd, c->current.h.chunk * RUDOLPH0_DATASIZE);
|
||||
} else {
|
||||
PRINTF("Wrong version, reseting chunk to 0\n");
|
||||
c->current.h.chunk = 0;
|
||||
cfs_seek(c->cfs_fd, 0);
|
||||
}
|
||||
read_new_datapacket(c);
|
||||
sabc_set_timer(&c->c, SENDING_TIME);
|
||||
|
@ -196,7 +190,6 @@ rudolph0_open(struct rudolph0_conn *c, u16_t channel,
|
|||
c->cb = cb;
|
||||
c->current.h.version = 0;
|
||||
c->state = STATE_RECEIVER;
|
||||
c->cfs_fd = -1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
|
@ -207,13 +200,9 @@ rudolph0_close(struct rudolph0_conn *c)
|
|||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
rudolph0_send(struct rudolph0_conn *c, int cfs_fd)
|
||||
rudolph0_send(struct rudolph0_conn *c)
|
||||
{
|
||||
if(c->cfs_fd != -1) {
|
||||
cfs_close(c->cfs_fd);
|
||||
}
|
||||
c->state = STATE_SENDER;
|
||||
c->cfs_fd = cfs_fd;
|
||||
c->current.h.version++;
|
||||
c->current.h.chunk = 0;
|
||||
c->current.h.type = TYPE_DATA;
|
||||
|
@ -222,6 +211,12 @@ rudolph0_send(struct rudolph0_conn *c, int cfs_fd)
|
|||
sabc_send_stubborn(&c->c, SENDING_TIME);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
rudolph0_stop(struct rudolph0_conn *c)
|
||||
{
|
||||
sabc_cancel(&c->c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
rudolph0_version(struct rudolph0_conn *c)
|
||||
{
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: rudolph0.h,v 1.2 2007/03/21 23:18:23 adamdunkels Exp $
|
||||
* $Id: rudolph0.h,v 1.3 2007/03/22 23:54:40 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -48,9 +48,17 @@
|
|||
|
||||
struct rudolph0_conn;
|
||||
|
||||
enum {
|
||||
RUDOLPH0_FLAG_NONE,
|
||||
RUDOLPH0_FLAG_NEWFILE,
|
||||
RUDOLPH0_FLAG_LASTCHUNK,
|
||||
};
|
||||
|
||||
struct rudolph0_callbacks {
|
||||
int (* new_file)(struct rudolph0_conn *c);
|
||||
void (* received_file)(struct rudolph0_conn *c);
|
||||
void (* write_chunk)(struct rudolph0_conn *c, int offset, int flag,
|
||||
char *data, int len);
|
||||
int (* read_chunk)(struct rudolph0_conn *c, int offset, char *to,
|
||||
int maxsize);
|
||||
};
|
||||
|
||||
#define RUDOLPH0_DATASIZE 64
|
||||
|
@ -71,7 +79,6 @@ struct rudolph0_conn {
|
|||
struct sabc_conn c;
|
||||
struct uabc_conn nackc;
|
||||
const struct rudolph0_callbacks *cb;
|
||||
int cfs_fd;
|
||||
u8_t state;
|
||||
struct rudolph0_datapacket current;
|
||||
};
|
||||
|
@ -79,7 +86,8 @@ 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, int cfs_fd);
|
||||
void rudolph0_send(struct rudolph0_conn *c);
|
||||
void rudolph0_stop(struct rudolph0_conn *c);
|
||||
|
||||
void rudolph0_set_version(struct rudolph0_conn *c, int version);
|
||||
int rudolph0_version(struct rudolph0_conn *c);
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: rudolph1.c,v 1.1 2007/03/21 23:14:40 adamdunkels Exp $
|
||||
* $Id: rudolph1.c,v 1.2 2007/03/22 23:54:40 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -81,10 +81,15 @@ enum {
|
|||
static int
|
||||
read_data(struct rudolph1_conn *c, char *dataptr, int chunk)
|
||||
{
|
||||
int len;
|
||||
int len = 0;
|
||||
|
||||
cfs_seek(c->cfs_fd, chunk * RUDOLPH1_DATASIZE);
|
||||
len = cfs_read(c->cfs_fd, dataptr, RUDOLPH1_DATASIZE);
|
||||
if(c->cb->read_chunk) {
|
||||
len = c->cb->read_chunk(c, chunk * RUDOLPH1_DATASIZE,
|
||||
dataptr, RUDOLPH1_DATASIZE);
|
||||
}
|
||||
|
||||
/* cfs_seek(c->cfs_fd, chunk * RUDOLPH1_DATASIZE);
|
||||
len = cfs_read(c->cfs_fd, dataptr, RUDOLPH1_DATASIZE);*/
|
||||
return len;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -108,12 +113,22 @@ format_data(struct rudolph1_conn *c, int chunk)
|
|||
static void
|
||||
write_data(struct rudolph1_conn *c, int chunk, u8_t *data, int datalen)
|
||||
{
|
||||
cfs_seek(c->cfs_fd, chunk * RUDOLPH1_DATASIZE);
|
||||
cfs_write(c->cfs_fd, data, datalen);
|
||||
if(chunk == 0) {
|
||||
c->cb->write_chunk(c, 0, RUDOLPH1_FLAG_NEWFILE, data, 0);
|
||||
}
|
||||
|
||||
|
||||
/* cfs_seek(c->cfs_fd, chunk * RUDOLPH1_DATASIZE);
|
||||
cfs_write(c->cfs_fd, data, datalen);*/
|
||||
if(datalen < RUDOLPH1_DATASIZE) {
|
||||
PRINTF("%d: get %d bytes, file complete\n",
|
||||
rimeaddr_node_addr.u16, datalen);
|
||||
c->cb->received_file(c, c->cfs_fd);
|
||||
/* c->cb->received_file(c, c->cfs_fd);*/
|
||||
c->cb->write_chunk(c, chunk * RUDOLPH1_DATASIZE,
|
||||
RUDOLPH1_FLAG_LASTCHUNK, data, datalen);
|
||||
} else {
|
||||
c->cb->write_chunk(c, chunk * RUDOLPH1_DATASIZE,
|
||||
RUDOLPH1_FLAG_NONE, data, datalen);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -138,34 +153,36 @@ 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);
|
||||
c->cfs_fd = c->cb->new_file(c);
|
||||
/* c->cfs_fd = c->cb->new_file(c);*/
|
||||
c->version = p->h.version;
|
||||
c->chunk = 1; /* Next chunk is 1. */
|
||||
if(c->cfs_fd != -1) {
|
||||
/* if(c->cfs_fd != -1) {*/
|
||||
if(p->h.chunk != 0) {
|
||||
send_nack(c);
|
||||
} else {
|
||||
write_data(c, 0, p->data, p->datalen);
|
||||
}
|
||||
}
|
||||
/* }*/
|
||||
} else if(p->h.version == c->version) {
|
||||
if(c->cfs_fd != -1) {
|
||||
/* if(c->cfs_fd != -1) {*/
|
||||
if(p->h.chunk == c->chunk) {
|
||||
PRINTF("%d: received chunk %d\n",
|
||||
rimeaddr_node_addr.u16, p->h.chunk);
|
||||
cfs_seek(c->cfs_fd, c->chunk * RUDOLPH1_DATASIZE);
|
||||
write_data(c, p->h.chunk, p->data, p->datalen);
|
||||
c->chunk++;
|
||||
/* cfs_seek(c->cfs_fd, c->chunk * RUDOLPH1_DATASIZE);
|
||||
cfs_write(c->cfs_fd, p->data, p->datalen);
|
||||
c->chunk++;
|
||||
if(p->datalen < RUDOLPH1_DATASIZE) {
|
||||
c->cb->received_file(c, c->cfs_fd);
|
||||
}
|
||||
}*/
|
||||
} else if(p->h.chunk > c->chunk) {
|
||||
PRINTF("%d: received chunk %d > %d, sending NACK\n",
|
||||
rimeaddr_node_addr.u16,
|
||||
p->h.chunk, c->chunk);
|
||||
send_nack(c);
|
||||
}
|
||||
}
|
||||
/* } */
|
||||
} else { /* p->h.version < c->current.h.version */
|
||||
/* Ignore packets with old version */
|
||||
}
|
||||
|
@ -254,9 +271,9 @@ rudolph1_close(struct rudolph1_conn *c)
|
|||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
rudolph1_send(struct rudolph1_conn *c, int cfs_fd)
|
||||
rudolph1_send(struct rudolph1_conn *c)
|
||||
{
|
||||
c->cfs_fd = cfs_fd;
|
||||
/* c->cfs_fd = cfs_fd;*/
|
||||
c->version++;
|
||||
c->chunk = 0;
|
||||
c->trickle_interval = TRICKLE_INTERVAL;
|
||||
|
@ -265,3 +282,11 @@ rudolph1_send(struct rudolph1_conn *c, int cfs_fd)
|
|||
ctimer_set(&c->t, DATA_INTERVAL, send_next_packet, c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
rudolph1_stop(struct rudolph1_conn *c)
|
||||
{
|
||||
/* XXX */
|
||||
ctimer_stop(&c->t);
|
||||
printf("rudolph1_stop: not implemented\n");
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: rudolph1.h,v 1.1 2007/03/21 23:14:40 adamdunkels Exp $
|
||||
* $Id: rudolph1.h,v 1.2 2007/03/22 23:54:40 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -48,9 +48,17 @@
|
|||
|
||||
struct rudolph1_conn;
|
||||
|
||||
enum {
|
||||
RUDOLPH1_FLAG_NONE,
|
||||
RUDOLPH1_FLAG_NEWFILE,
|
||||
RUDOLPH1_FLAG_LASTCHUNK,
|
||||
};
|
||||
|
||||
struct rudolph1_callbacks {
|
||||
int (* new_file)(struct rudolph1_conn *c);
|
||||
void (* received_file)(struct rudolph1_conn *c, int cfs_fd);
|
||||
void (* write_chunk)(struct rudolph1_conn *c, int offset, int flag,
|
||||
char *data, int len);
|
||||
int (* read_chunk)(struct rudolph1_conn *c, int offset, char *to,
|
||||
int maxsize);
|
||||
};
|
||||
|
||||
struct rudolph1_conn {
|
||||
|
@ -58,7 +66,6 @@ struct rudolph1_conn {
|
|||
struct uabc_conn uabc;
|
||||
const struct rudolph1_callbacks *cb;
|
||||
struct ctimer t;
|
||||
int cfs_fd;
|
||||
u16_t chunk;
|
||||
u8_t version;
|
||||
u8_t trickle_interval;
|
||||
|
@ -68,6 +75,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, int cfs_fd);
|
||||
void rudolph1_send(struct rudolph1_conn *c);
|
||||
void rudolph1_stop(struct rudolph1_conn *c);
|
||||
|
||||
#endif /* __RUDOLPH1_H__ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue