From 18fbc7643353647a285318ae257bae0ba0b40dd1 Mon Sep 17 00:00:00 2001 From: adamdunkels Date: Wed, 21 Mar 2007 23:18:23 +0000 Subject: [PATCH] Bugfixes, added version API, larger data size --- apps/rudolph/rudolph0.c | 34 +++++++++++++++++++++++++++++----- apps/rudolph/rudolph0.h | 9 ++++++--- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/apps/rudolph/rudolph0.c b/apps/rudolph/rudolph0.c index 19acc72b4..25836c03f 100644 --- a/apps/rudolph/rudolph0.c +++ b/apps/rudolph/rudolph0.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: rudolph0.c,v 1.1 2007/03/20 12:25:27 adamdunkels Exp $ + * $Id: rudolph0.c,v 1.2 2007/03/21 23:18:23 adamdunkels Exp $ */ /** @@ -57,6 +57,8 @@ enum { STATE_SENDER, }; +#define VERSION_LT(a, b) ((signed char)((a) - (b)) < 0) + #define DEBUG 0 #if DEBUG #include @@ -74,7 +76,7 @@ read_new_datapacket(struct rudolph0_conn *c) len = cfs_read(c->cfs_fd, c->current.data, RUDOLPH0_DATASIZE); c->current.datalen = len; - PRINTF("read_new_datapacket len %d\n", c->current.datalen); + PRINTF("read_new_datapacket len %d\n", len); } /*---------------------------------------------------------------------------*/ static void @@ -104,7 +106,7 @@ sent(struct sabc_conn *sabc) read_new_datapacket(c); } else { sabc_set_timer(&c->c, STEADY_TIME); - PRINTF("Sending the same data chunk next time datalen %d, %d\n", + PRINTF("Steady: Sending the same data chunk next time datalen %d, %d\n", c->current.datalen, RUDOLPH0_DATASIZE); } } @@ -120,8 +122,11 @@ recv(struct sabc_conn *sabc) }*/ if(p->h.type == TYPE_DATA) { - if(p->h.version > c->current.h.version) { + 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; @@ -140,8 +145,11 @@ recv(struct sabc_conn *sabc) cfs_write(c->cfs_fd, p->data, p->datalen); c->current.h.chunk++; if(p->datalen < RUDOLPH0_DATASIZE) { - c->cb->received_file(c, c->cfs_fd); + 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); @@ -188,6 +196,7 @@ 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 @@ -200,6 +209,9 @@ rudolph0_close(struct rudolph0_conn *c) void rudolph0_send(struct rudolph0_conn *c, int cfs_fd) { + if(c->cfs_fd != -1) { + cfs_close(c->cfs_fd); + } c->state = STATE_SENDER; c->cfs_fd = cfs_fd; c->current.h.version++; @@ -210,3 +222,15 @@ rudolph0_send(struct rudolph0_conn *c, int cfs_fd) sabc_send_stubborn(&c->c, SENDING_TIME); } /*---------------------------------------------------------------------------*/ +int +rudolph0_version(struct rudolph0_conn *c) +{ + return c->current.h.version; +} +/*---------------------------------------------------------------------------*/ +void +rudolph0_set_version(struct rudolph0_conn *c, int version) +{ + c->current.h.version = version; +} +/*---------------------------------------------------------------------------*/ diff --git a/apps/rudolph/rudolph0.h b/apps/rudolph/rudolph0.h index 20cf0fb96..295f52f84 100644 --- a/apps/rudolph/rudolph0.h +++ b/apps/rudolph/rudolph0.h @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: rudolph0.h,v 1.1 2007/03/20 12:25:27 adamdunkels Exp $ + * $Id: rudolph0.h,v 1.2 2007/03/21 23:18:23 adamdunkels Exp $ */ /** @@ -50,10 +50,10 @@ struct rudolph0_conn; struct rudolph0_callbacks { int (* new_file)(struct rudolph0_conn *c); - void (* received_file)(struct rudolph0_conn *c, int cfs_fd); + void (* received_file)(struct rudolph0_conn *c); }; -#define RUDOLPH0_DATASIZE 32 +#define RUDOLPH0_DATASIZE 64 struct rudolph0_hdr { u8_t type; @@ -81,4 +81,7 @@ void rudolph0_open(struct rudolph0_conn *c, u16_t channel, void rudolph0_close(struct rudolph0_conn *c); void rudolph0_send(struct rudolph0_conn *c, int cfs_fd); +void rudolph0_set_version(struct rudolph0_conn *c, int version); +int rudolph0_version(struct rudolph0_conn *c); + #endif /* __RUDOLPH0_H__ */