Merge pull request #1001 from adamdunkels/pr/queuebuf-no-ref

Cleanup: remove the obsolete reference packetbuf
This commit is contained in:
Nicolas Tsiftes 2015-05-03 16:35:17 +02:00
commit f7ca4b41a9
16 changed files with 52 additions and 1232 deletions

View file

@ -9,7 +9,7 @@ shell_src = shell.c shell-reboot.c shell-vars.c shell-ps.c \
shell_dsc = shell-dsc.c shell_dsc = shell-dsc.c
ifeq ($(CONTIKI_WITH_RIME),1) ifeq ($(CONTIKI_WITH_RIME),1)
shell_src += shell-rime.c shell-sendtest.c shell-netfile.c \ shell_src += shell-rime.c shell-sendtest.c \
shell-rime-ping.c shell-rime-sniff.c shell-rime-netcmd.c \ shell-rime-ping.c shell-rime-sniff.c shell-rime-netcmd.c \
shell-rime-debug.c shell-rime-debug-runicast.c \ shell-rime-debug.c shell-rime-debug-runicast.c \
shell-rime-sendcmd.c shell-download.c shell-rime-neighbors.c \ shell-rime-sendcmd.c shell-download.c shell-rime-neighbors.c \

View file

@ -1,179 +0,0 @@
/*
* Copyright (c) 2008, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
/**
* \file
* A brief description of what this file is.
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "contiki.h"
#include "shell-netfile.h"
#include "net/rime/rime.h"
#include "net/rime/rudolph0.h"
#include "dev/leds.h"
#include "cfs/cfs.h"
#include <stdio.h>
#include <string.h>
#define FILENAME_LEN 20
static struct rudolph0_conn rudolph0_conn;
static char filename[FILENAME_LEN];
static int receiving_file;
static struct pt recvnetfilept;
/*---------------------------------------------------------------------------*/
PROCESS(shell_netfile_process, "netfile");
SHELL_COMMAND(netfile_command,
"netfile",
"netfile: send file to entire network",
&shell_netfile_process);
PROCESS(shell_recvnetfile_process, "recvnetfile");
SHELL_COMMAND(recvnetfile_command,
"recvnetfile",
"recvnetfile: receive file from network and print to output",
&shell_recvnetfile_process);
/*---------------------------------------------------------------------------*/
static int
write_chunk_pt(struct rudolph0_conn *c, int offset, int flag,
uint8_t *data, int datalen)
{
PT_BEGIN(&recvnetfilept);
PT_WAIT_UNTIL(&recvnetfilept, receiving_file);
leds_on(LEDS_YELLOW);
leds_on(LEDS_RED);
PT_WAIT_UNTIL(&recvnetfilept, flag == RUDOLPH0_FLAG_NEWFILE);
leds_off(LEDS_RED);
do {
if(datalen > 0) {
shell_output(&recvnetfile_command, data, datalen, "", 0);
/* printf("write_chunk wrote %d bytes at %d\n", datalen, offset);*/
}
PT_YIELD(&recvnetfilept);
} while(flag != RUDOLPH0_FLAG_LASTCHUNK);
shell_output(&recvnetfile_command, data, datalen, "", 0);
/* printf("write_chunk wrote %d bytes at %d\n", datalen, offset);*/
shell_output(&recvnetfile_command, "", 0, "", 0);
leds_off(LEDS_YELLOW);
receiving_file = 0;
process_post(&shell_recvnetfile_process, PROCESS_EVENT_CONTINUE, NULL);
PT_END(&recvnetfilept);
}
static void
write_chunk(struct rudolph0_conn *c, int offset, int flag,
uint8_t *data, int datalen)
{
write_chunk_pt(c, offset, flag, data, datalen);
}
static int
read_chunk(struct rudolph0_conn *c, int offset, uint8_t *to, int maxsize)
{
int ret;
int fd;
fd = cfs_open(filename, CFS_READ);
cfs_seek(fd, offset, CFS_SEEK_SET);
ret = cfs_read(fd, to, maxsize);
/* printf("read_chunk %d bytes at %d, %d\n", ret, offset, (unsigned char)to[0]);*/
cfs_close(fd);
return ret;
}
CC_CONST_FUNCTION static struct rudolph0_callbacks rudolph0_callbacks =
{/*(void (*)(struct rudolph0_conn *, int, int, uint8_t *, int))*/
write_chunk,
read_chunk};
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_netfile_process, ev, data)
{
int fd;
PROCESS_BEGIN();
if(data != NULL) {
rudolph0_send(&rudolph0_conn, CLOCK_SECOND);
strncpy(filename, data, FILENAME_LEN);
fd = cfs_open(filename, CFS_READ);
if(fd < 0) {
shell_output_str(&netfile_command, "netfile: could not open file ", filename);
} else {
cfs_close(fd);
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_recvnetfile_process, ev, data)
{
PROCESS_BEGIN();
PT_INIT(&recvnetfilept);
receiving_file = 1;
while(1) {
struct shell_input *input;
PROCESS_WAIT_EVENT();
if(ev == shell_event_input) {
input = data;
if(input->len1 + input->len2 == 0) {
receiving_file = 0;
PROCESS_EXIT();
}
} else if(receiving_file == 0) {
PROCESS_EXIT();
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
void
shell_netfile_init(void)
{
receiving_file = 0;
shell_register_command(&netfile_command);
shell_register_command(&recvnetfile_command);
rudolph0_open(&rudolph0_conn, SHELL_RIME_CHANNEL_NETFILE,
&rudolph0_callbacks);
}
/*---------------------------------------------------------------------------*/

View file

@ -1,47 +0,0 @@
/*
* Copyright (c) 2008, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
/**
* \file
* A brief description of what this file is.
* \author
* Adam Dunkels <adam@sics.se>
*/
#ifndef SHELL_NETFILE_H_
#define SHELL_NETFILE_H_
#include "shell.h"
void shell_netfile_init(void);
#endif /* SHELL_NETFILE_H_ */

View file

@ -382,7 +382,6 @@ struct shell_input {
#include "shell-httpd.h" #include "shell-httpd.h"
#include "shell-irc.h" #include "shell-irc.h"
#include "shell-memdebug.h" #include "shell-memdebug.h"
#include "shell-netfile.h"
#include "shell-netperf.h" #include "shell-netperf.h"
#include "shell-netstat.h" #include "shell-netstat.h"
#include "shell-ping.h" #include "shell-ping.h"

View file

@ -106,10 +106,7 @@ packetbuf_compact(void)
{ {
int i, len; int i, len;
if(packetbuf_is_reference()) { if(bufptr > 0) {
memcpy(&packetbuf[PACKETBUF_HDR_SIZE], packetbuf_reference_ptr(),
packetbuf_datalen());
} else if(bufptr > 0) {
len = packetbuf_datalen() + PACKETBUF_HDR_SIZE; len = packetbuf_datalen() + PACKETBUF_HDR_SIZE;
for(i = PACKETBUF_HDR_SIZE; i < len; i++) { for(i = PACKETBUF_HDR_SIZE; i < len; i++) {
packetbuf[i] = packetbuf[bufptr + i]; packetbuf[i] = packetbuf[bufptr + i];
@ -215,26 +212,6 @@ packetbuf_hdrptr(void)
return (void *)(&packetbuf[hdrptr]); return (void *)(&packetbuf[hdrptr]);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void
packetbuf_reference(void *ptr, uint16_t len)
{
packetbuf_clear();
packetbufptr = ptr;
buflen = len;
}
/*---------------------------------------------------------------------------*/
int
packetbuf_is_reference(void)
{
return packetbufptr != &packetbuf[PACKETBUF_HDR_SIZE];
}
/*---------------------------------------------------------------------------*/
void *
packetbuf_reference_ptr(void)
{
return packetbufptr;
}
/*---------------------------------------------------------------------------*/
uint16_t uint16_t
packetbuf_datalen(void) packetbuf_datalen(void)
{ {

View file

@ -181,52 +181,12 @@ uint16_t packetbuf_totlen(void);
*/ */
void packetbuf_set_datalen(uint16_t len); void packetbuf_set_datalen(uint16_t len);
/**
* \brief Point the packetbuf to external data
* \param ptr A pointer to the external data
* \param len The length of the external data
*
* For outbound packets, the packetbuf consists of two
* parts: header and data. This function is used to make
* the packetbuf point to external data. The function also
* specifies the length of the external data that the
* packetbuf references.
*/
void packetbuf_reference(void *ptr, uint16_t len);
/**
* \brief Check if the packetbuf references external data
* \retval Non-zero if the packetbuf references external data, zero otherwise.
*
* For outbound packets, the packetbuf consists of two
* parts: header and data. This function is used to check
* if the packetbuf points to external data that has
* previously been referenced with packetbuf_reference().
*
*/
int packetbuf_is_reference(void);
/**
* \brief Get a pointer to external data referenced by the packetbuf
* \retval A pointer to the external data
*
* For outbound packets, the packetbuf consists of two
* parts: header and data. The data may point to external
* data that has previously been referenced with
* packetbuf_reference(). This function is used to get a
* pointer to the external data.
*
*/
void *packetbuf_reference_ptr(void);
/** /**
* \brief Compact the packetbuf * \brief Compact the packetbuf
* *
* This function compacts the packetbuf by copying the data * This function compacts the packetbuf by copying the data
* portion of the packetbuf so that becomes consecutive to * portion of the packetbuf so that becomes consecutive to
* the header. It also copies external data that has * the header.
* previously been referenced with packetbuf_reference()
* into the packetbuf.
* *
* This function is called by the Rime code before a * This function is called by the Rime code before a
* packet is to be sent by a device driver. This assures * packet is to be sent by a device driver. This assures
@ -257,9 +217,7 @@ int packetbuf_copyfrom(const void *from, uint16_t len);
* *
* This function copies the packetbuf to an external * This function copies the packetbuf to an external
* buffer. Both the data portion and the header portion of * buffer. Both the data portion and the header portion of
* the packetbuf is copied. If the packetbuf referenced * the packetbuf is copied.
* external data (referenced with packetbuf_reference()) the
* external data is copied.
* *
* The external buffer to which the packetbuf is to be * The external buffer to which the packetbuf is to be
* copied must be able to accomodate at least * copied must be able to accomodate at least

View file

@ -43,18 +43,13 @@
*/ */
#include "contiki-net.h" #include "contiki-net.h"
#if WITH_SWAP #if WITH_SWAP
#include "cfs/cfs.h" #include "cfs/cfs.h"
#endif #endif
#include <string.h> /* for memcpy() */ #include <string.h> /* for memcpy() */
#ifdef QUEUEBUF_CONF_REF_NUM
#define QUEUEBUF_REF_NUM QUEUEBUF_CONF_REF_NUM
#else
#define QUEUEBUF_REF_NUM 2
#endif
/* Structure pointing to a buffer either stored /* Structure pointing to a buffer either stored
in RAM or swapped in CFS */ in RAM or swapped in CFS */
struct queuebuf { struct queuebuf {
@ -83,15 +78,7 @@ struct queuebuf_data {
struct packetbuf_addr addrs[PACKETBUF_NUM_ADDRS]; struct packetbuf_addr addrs[PACKETBUF_NUM_ADDRS];
}; };
struct queuebuf_ref {
uint16_t len;
uint8_t *ref;
uint8_t hdr[PACKETBUF_HDR_SIZE];
uint8_t hdrlen;
};
MEMB(bufmem, struct queuebuf, QUEUEBUF_NUM); MEMB(bufmem, struct queuebuf, QUEUEBUF_NUM);
MEMB(refbufmem, struct queuebuf_ref, QUEUEBUF_REF_NUM);
MEMB(buframmem, struct queuebuf_data, QUEUEBUFRAM_NUM); MEMB(buframmem, struct queuebuf_data, QUEUEBUFRAM_NUM);
#if WITH_SWAP #if WITH_SWAP
@ -144,7 +131,7 @@ LIST(queuebuf_list);
#endif /* QUEUEBUF_CONF_STATS */ #endif /* QUEUEBUF_CONF_STATS */
#if QUEUEBUF_STATS #if QUEUEBUF_STATS
uint8_t queuebuf_len, queuebuf_ref_len, queuebuf_max_len; uint8_t queuebuf_len, queuebuf_max_len;
#endif /* QUEUEBUF_STATS */ #endif /* QUEUEBUF_STATS */
#if WITH_SWAP #if WITH_SWAP
@ -301,21 +288,16 @@ queuebuf_init(void)
#endif #endif
memb_init(&buframmem); memb_init(&buframmem);
memb_init(&bufmem); memb_init(&bufmem);
memb_init(&refbufmem);
#if QUEUEBUF_STATS #if QUEUEBUF_STATS
queuebuf_max_len = QUEUEBUF_NUM; queuebuf_max_len = 0;
#endif /* QUEUEBUF_STATS */ #endif /* QUEUEBUF_STATS */
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
queuebuf_numfree(void) queuebuf_numfree(void)
{ {
if(packetbuf_is_reference()) {
return memb_numfree(&refbufmem);
} else {
return memb_numfree(&bufmem); return memb_numfree(&bufmem);
} }
}
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if QUEUEBUF_DEBUG #if QUEUEBUF_DEBUG
struct queuebuf * struct queuebuf *
@ -326,22 +308,7 @@ queuebuf_new_from_packetbuf(void)
#endif /* QUEUEBUF_DEBUG */ #endif /* QUEUEBUF_DEBUG */
{ {
struct queuebuf *buf; struct queuebuf *buf;
struct queuebuf_ref *rbuf;
if(packetbuf_is_reference()) {
rbuf = memb_alloc(&refbufmem);
if(rbuf != NULL) {
#if QUEUEBUF_STATS
++queuebuf_ref_len;
#endif /* QUEUEBUF_STATS */
rbuf->len = packetbuf_datalen();
rbuf->ref = packetbuf_reference_ptr();
rbuf->hdrlen = packetbuf_copyto_hdr(rbuf->hdr);
} else {
PRINTF("queuebuf_new_from_packetbuf: could not allocate a reference queuebuf\n");
}
return (struct queuebuf *)rbuf;
} else {
struct queuebuf_data *buframptr; struct queuebuf_data *buframptr;
buf = memb_alloc(&bufmem); buf = memb_alloc(&bufmem);
if(buf != NULL) { if(buf != NULL) {
@ -387,12 +354,9 @@ queuebuf_new_from_packetbuf(void)
#if QUEUEBUF_STATS #if QUEUEBUF_STATS
++queuebuf_len; ++queuebuf_len;
PRINTF("queuebuf len %d\n", queuebuf_len); PRINTF("#A q=%d\n", queuebuf_len);
printf("#A q=%d\n", queuebuf_len); if(queuebuf_len > queuebuf_max_len) {
if(queuebuf_len == queuebuf_max_len + 1) { queuebuf_max_len = queuebuf_len;
queuebuf_free(buf);
queuebuf_len--;
return NULL;
} }
#endif /* QUEUEBUF_STATS */ #endif /* QUEUEBUF_STATS */
@ -401,7 +365,6 @@ queuebuf_new_from_packetbuf(void)
} }
return buf; return buf;
} }
}
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
queuebuf_update_attr_from_packetbuf(struct queuebuf *buf) queuebuf_update_attr_from_packetbuf(struct queuebuf *buf)
@ -444,47 +407,30 @@ queuebuf_free(struct queuebuf *buf)
memb_free(&bufmem, buf); memb_free(&bufmem, buf);
#if QUEUEBUF_STATS #if QUEUEBUF_STATS
--queuebuf_len; --queuebuf_len;
printf("#A q=%d\n", queuebuf_len); PRINTF("#A q=%d\n", queuebuf_len);
#endif /* QUEUEBUF_STATS */ #endif /* QUEUEBUF_STATS */
#if QUEUEBUF_DEBUG #if QUEUEBUF_DEBUG
list_remove(queuebuf_list, buf); list_remove(queuebuf_list, buf);
#endif /* QUEUEBUF_DEBUG */ #endif /* QUEUEBUF_DEBUG */
} else if(memb_inmemb(&refbufmem, buf)) {
memb_free(&refbufmem, buf);
#if QUEUEBUF_STATS
--queuebuf_ref_len;
#endif /* QUEUEBUF_STATS */
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
queuebuf_to_packetbuf(struct queuebuf *b) queuebuf_to_packetbuf(struct queuebuf *b)
{ {
struct queuebuf_ref *r;
if(memb_inmemb(&bufmem, b)) { if(memb_inmemb(&bufmem, b)) {
struct queuebuf_data *buframptr = queuebuf_load_to_ram(b); struct queuebuf_data *buframptr = queuebuf_load_to_ram(b);
packetbuf_copyfrom(buframptr->data, buframptr->len); packetbuf_copyfrom(buframptr->data, buframptr->len);
packetbuf_attr_copyfrom(buframptr->attrs, buframptr->addrs); packetbuf_attr_copyfrom(buframptr->attrs, buframptr->addrs);
} else if(memb_inmemb(&refbufmem, b)) {
r = (struct queuebuf_ref *)b;
packetbuf_clear();
packetbuf_copyfrom(r->ref, r->len);
packetbuf_hdralloc(r->hdrlen);
memcpy(packetbuf_hdrptr(), r->hdr, r->hdrlen);
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void * void *
queuebuf_dataptr(struct queuebuf *b) queuebuf_dataptr(struct queuebuf *b)
{ {
struct queuebuf_ref *r;
if(memb_inmemb(&bufmem, b)) { if(memb_inmemb(&bufmem, b)) {
struct queuebuf_data *buframptr = queuebuf_load_to_ram(b); struct queuebuf_data *buframptr = queuebuf_load_to_ram(b);
return buframptr->data; return buframptr->data;
} else if(memb_inmemb(&refbufmem, b)) {
r = (struct queuebuf_ref *)b;
return r->ref;
} }
return NULL; return NULL;
} }

View file

@ -1,242 +0,0 @@
/*
* Copyright (c) 2007, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
/**
* \file
* Rudolph0: a simple block data flooding protocol
* \author
* Adam Dunkels <adam@sics.se>
*/
/**
* \addtogroup rudolph0
* @{
*/
#include <stddef.h> /* for offsetof */
#include "net/rime/rime.h"
#include "net/rime/rudolph0.h"
#define STEADY_TIME CLOCK_SECOND * 2
#define DEFAULT_SEND_INTERVAL CLOCK_SECOND / 2
enum {
TYPE_DATA,
TYPE_NACK,
};
enum {
STATE_RECEIVER,
STATE_SENDER,
};
#define VERSION_LT(a, b) ((signed char)((a) - (b)) < 0)
#define DEBUG 0
#if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
/*---------------------------------------------------------------------------*/
static void
read_new_datapacket(struct rudolph0_conn *c)
{
int len = 0;
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);
}
/*---------------------------------------------------------------------------*/
static void
send_nack(struct rudolph0_conn *c)
{
struct rudolph0_hdr *hdr;
packetbuf_clear();
packetbuf_hdralloc(sizeof(struct rudolph0_hdr));
hdr = packetbuf_hdrptr();
hdr->type = TYPE_NACK;
hdr->version = c->current.h.version;
hdr->chunk = c->current.h.chunk;
PRINTF("Sending nack for %d:%d\n", hdr->version, hdr->chunk);
polite_send(&c->nackc, c->send_interval / 2, sizeof(struct rudolph0_hdr));
}
/*---------------------------------------------------------------------------*/
static void
sent(struct stbroadcast_conn *stbroadcast)
{
struct rudolph0_conn *c = (struct rudolph0_conn *)stbroadcast;
if(c->current.datalen == RUDOLPH0_DATASIZE) {
c->current.h.chunk++;
PRINTF("Sending data chunk %d next time\n", c->current.h.chunk);
read_new_datapacket(c);
} else {
stbroadcast_set_timer(&c->c, STEADY_TIME);
PRINTF("Steady: Sending the same data chunk next time datalen %d, %d\n",
c->current.datalen, RUDOLPH0_DATASIZE);
}
}
/*---------------------------------------------------------------------------*/
static void
recv(struct stbroadcast_conn *stbroadcast)
{
struct rudolph0_conn *c = (struct rudolph0_conn *)stbroadcast;
struct rudolph0_datapacket *p = packetbuf_dataptr();
if(p->h.type == TYPE_DATA) {
if(c->current.h.version != p->h.version) {
PRINTF("rudolph0 new version %d\n", p->h.version);
c->current.h.version = p->h.version;
c->current.h.chunk = 0;
c->cb->write_chunk(c, 0, RUDOLPH0_FLAG_NEWFILE, p->data, 0);
if(p->h.chunk != 0) {
send_nack(c);
} else {
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(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 */
}
}
}
/*---------------------------------------------------------------------------*/
static void
recv_nack(struct polite_conn *polite)
{
struct rudolph0_conn *c = (struct rudolph0_conn *)
((char *)polite - offsetof(struct rudolph0_conn,
nackc));
struct rudolph0_datapacket *p = packetbuf_dataptr();
if(p->h.type == TYPE_NACK && c->state == STATE_SENDER) {
if(p->h.version == c->current.h.version) {
PRINTF("Reseting chunk to %d\n", p->h.chunk);
c->current.h.chunk = p->h.chunk;
} else {
PRINTF("Wrong version, reseting chunk to 0\n");
c->current.h.chunk = 0;
}
read_new_datapacket(c);
stbroadcast_set_timer(&c->c, c->send_interval);
}
}
/*---------------------------------------------------------------------------*/
static const struct polite_callbacks polite = { recv_nack, 0, 0 };
static const struct stbroadcast_callbacks stbroadcast = { recv, sent };
/*---------------------------------------------------------------------------*/
void
rudolph0_open(struct rudolph0_conn *c, uint16_t channel,
const struct rudolph0_callbacks *cb)
{
stbroadcast_open(&c->c, channel, &stbroadcast);
polite_open(&c->nackc, channel + 1, &polite);
c->cb = cb;
c->current.h.version = 0;
c->state = STATE_RECEIVER;
c->send_interval = DEFAULT_SEND_INTERVAL;
}
/*---------------------------------------------------------------------------*/
void
rudolph0_close(struct rudolph0_conn *c)
{
stbroadcast_close(&c->c);
polite_close(&c->nackc);
}
/*---------------------------------------------------------------------------*/
void
rudolph0_send(struct rudolph0_conn *c, clock_time_t send_interval)
{
c->state = STATE_SENDER;
c->current.h.version++;
c->current.h.version++;
c->current.h.chunk = 0;
c->current.h.type = TYPE_DATA;
read_new_datapacket(c);
packetbuf_reference(&c->current, sizeof(struct rudolph0_datapacket));
c->send_interval = send_interval;
stbroadcast_send_stubborn(&c->c, c->send_interval);
}
/*---------------------------------------------------------------------------*/
void
rudolph0_force_restart(struct rudolph0_conn *c)
{
c->current.h.chunk = 0;
send_nack(c);
}
/*---------------------------------------------------------------------------*/
void
rudolph0_stop(struct rudolph0_conn *c)
{
stbroadcast_cancel(&c->c);
}
/*---------------------------------------------------------------------------*/
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;
}
/*---------------------------------------------------------------------------*/
/** @} */

View file

@ -1,122 +0,0 @@
/*
* Copyright (c) 2007, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
/**
* \file
* Header file for the single-hop reliable bulk data transfer module
* \author
* Adam Dunkels <adam@sics.se>
*/
/**
* \addtogroup rime
* @{
*/
/**
* \defgroup rudolph0 Single-hop reliable bulk data transfer (rudolph0)
* @{
*
* The rudolph0 module implements a single-hop reliable bulk data
* transfer mechanism.
*
* \section rudolph0-channels Channels
*
* The rudolph0 module uses 2 channels; one for data packets and one
* for NACK and repair packets.
*
*/
#ifndef RUDOLPH0_H_
#define RUDOLPH0_H_
#include "net/rime/stbroadcast.h"
#include "net/rime/polite.h"
struct rudolph0_conn;
enum {
RUDOLPH0_FLAG_NONE,
RUDOLPH0_FLAG_NEWFILE,
RUDOLPH0_FLAG_LASTCHUNK,
};
struct rudolph0_callbacks {
void (* write_chunk)(struct rudolph0_conn *c, int offset, int flag,
uint8_t *data, int len);
int (* read_chunk)(struct rudolph0_conn *c, int offset, uint8_t *to,
int maxsize);
};
#ifdef RUDOLPH0_CONF_DATASIZE
#define RUDOLPH0_DATASIZE RUDOLPH0_CONF_DATASIZE
#else
#define RUDOLPH0_DATASIZE 64
#endif
struct rudolph0_hdr {
uint8_t type;
uint8_t version;
uint16_t chunk;
};
struct rudolph0_datapacket {
struct rudolph0_hdr h;
uint8_t datalen;
uint8_t data[RUDOLPH0_DATASIZE];
};
struct rudolph0_conn {
struct stbroadcast_conn c;
struct polite_conn nackc;
const struct rudolph0_callbacks *cb;
clock_time_t send_interval;
uint8_t state;
struct rudolph0_datapacket current;
};
void rudolph0_open(struct rudolph0_conn *c, uint16_t channel,
const struct rudolph0_callbacks *cb);
void rudolph0_close(struct rudolph0_conn *c);
void rudolph0_send(struct rudolph0_conn *c, clock_time_t interval);
void rudolph0_stop(struct rudolph0_conn *c);
/* Force the sender to restart sending the file from the start. */
void rudolph0_force_restart(struct rudolph0_conn *c);
void rudolph0_set_version(struct rudolph0_conn *c, int version);
int rudolph0_version(struct rudolph0_conn *c);
#endif /* RUDOLPH0_H_ */
/** @} */
/** @} */

View file

@ -11,7 +11,6 @@
/** \example example-mesh.c */ /** \example example-mesh.c */
/** \example example-multihop.c */ /** \example example-multihop.c */
/** \example example-rucb.c */ /** \example example-rucb.c */
/** \example example-rudolph0.c */
/** \example example-rudolph1.c */ /** \example example-rudolph1.c */
/** \example example-rudolph2.c */ /** \example example-rudolph2.c */
/** \example example-runicast.c */ /** \example example-runicast.c */

View file

@ -66,7 +66,6 @@ PROCESS_THREAD(example_shell_process, ev, data)
shell_file_init(); shell_file_init();
shell_httpd_init(); shell_httpd_init();
shell_irc_init(); shell_irc_init();
shell_netfile_init();
/*shell_ping_init();*/ /* uIP ping */ /*shell_ping_init();*/ /* uIP ping */
shell_power_init(); shell_power_init();
/*shell_profile_init();*/ /*shell_profile_init();*/

View file

@ -1,7 +1,7 @@
CONTIKI = ../.. CONTIKI = ../..
all: example-abc example-mesh example-collect example-trickle example-polite \ all: example-abc example-mesh example-collect example-trickle example-polite \
example-rudolph0 example-rudolph1 example-rudolph2 example-rucb \ example-rudolph1 example-rudolph2 example-rucb \
example-runicast example-unicast example-neighbors example-runicast example-unicast example-neighbors
CONTIKI_WITH_RIME = 1 CONTIKI_WITH_RIME = 1

View file

@ -1,150 +0,0 @@
/*
* Copyright (c) 2007, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
/**
* \file
* Testing the rudolph0 code in Rime
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "contiki.h"
#include "cfs/cfs.h"
#include "net/rime/rudolph0.h"
#include "dev/button-sensor.h"
#include "dev/leds.h"
#include <stdio.h>
#define FILESIZE 200
/*---------------------------------------------------------------------------*/
PROCESS(example_rudolph0_process, "Rudolph0 example");
AUTOSTART_PROCESSES(&example_rudolph0_process);
/*---------------------------------------------------------------------------*/
static void
write_chunk(struct rudolph0_conn *c, int offset, int flag,
uint8_t *data, int datalen)
{
int fd;
if(flag == RUDOLPH0_FLAG_NEWFILE) {
/* printf("+++ rudolph0 new file incoming at %lu\n", clock_time());*/
leds_on(LEDS_RED);
fd = cfs_open("codeprop.out", CFS_WRITE);
} else {
fd = cfs_open("codeprop.out", CFS_WRITE + CFS_APPEND);
}
if(datalen > 0) {
int ret;
cfs_seek(fd, offset, CFS_SEEK_SET);
ret = cfs_write(fd, data, datalen);
/* printf("write_chunk wrote %d bytes at %d, %d\n", ret, offset, (unsigned char)data[0]);*/
}
cfs_close(fd);
if(flag == RUDOLPH0_FLAG_LASTCHUNK) {
int i;
/* printf("+++ rudolph0 entire file received at %lu\n", clock_time());*/
leds_off(LEDS_RED);
leds_on(LEDS_YELLOW);
fd = cfs_open("hej", CFS_READ);
for(i = 0; i < FILESIZE; ++i) {
unsigned char buf;
cfs_read(fd, &buf, 1);
if(buf != (unsigned char)i) {
printf("error: diff at %d, %d != %d\n", i, i, buf);
break;
}
}
cfs_close(fd);
}
}
static int
read_chunk(struct rudolph0_conn *c, int offset, uint8_t *to, int maxsize)
{
int fd;
int ret;
fd = cfs_open("hej", CFS_READ);
cfs_seek(fd, offset, CFS_SEEK_SET);
ret = cfs_read(fd, to, maxsize);
/* printf("read_chunk %d bytes at %d, %d\n", ret, offset, (unsigned char)to[0]);*/
cfs_close(fd);
return ret;
}
const static struct rudolph0_callbacks rudolph0_call = {write_chunk,
read_chunk};
static struct rudolph0_conn rudolph0;
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(example_rudolph0_process, ev, data)
{
static int fd;
PROCESS_EXITHANDLER(rudolph0_close(&rudolph0);)
PROCESS_BEGIN();
PROCESS_PAUSE();
rudolph0_open(&rudolph0, 138, &rudolph0_call);
SENSORS_ACTIVATE(button_sensor);
while(1) {
PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event &&
data == &button_sensor);
{
int i;
fd = cfs_open("hej", CFS_WRITE);
for(i = 0; i < FILESIZE; i++) {
unsigned char buf = i;
cfs_write(fd, &buf, 1);
}
cfs_close(fd);
}
rudolph0_send(&rudolph0, CLOCK_SECOND / 4);
PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event &&
data == &button_sensor);
rudolph0_stop(&rudolph0);
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View file

@ -58,7 +58,6 @@ PROCESS_THREAD(test_shell_process, ev, data)
shell_coffee_init(); shell_coffee_init();
shell_exec_init(); shell_exec_init();
shell_file_init(); shell_file_init();
shell_netfile_init();
shell_ps_init(); shell_ps_init();
shell_rime_init(); shell_rime_init();
shell_rime_netcmd_init(); shell_rime_netcmd_init();

View file

@ -1,316 +0,0 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
#include <stdio.h>
#include <string.h>
#include "contiki.h"
#include "sys/etimer.h"
#include "loader/elfloader.h"
#include "net/ip/uip.h"
#include "dev/leds.h"
#include "cfs/cfs.h"
#include "codeprop.h"
#include "net/rime/rudolph0.h"
#include <io.h>
#define DEBUG 0
#if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
PROCESS(tcp_loader_process, "TCP loader");
AUTOSTART_PROCESSES(&tcp_loader_process);
static
struct codeprop_state {
uint16_t addr;
uint16_t len;
struct pt tcpthread_pt;
int fd;
} s;
static char msg[30 + 10];
static struct rudolph0_conn rudolph0;
/*---------------------------------------------------------------------*/
static int
start_program(void)
{
/* Link, load, and start new program. */
int ret;
s.fd = cfs_open("codeprop.out", CFS_READ);
ret = elfloader_load(s.fd);
/* XXX: Interrupts seems to be turned off a little too long during the
ELF loading process, so we need to "manually" trigger a timer
interrupt here. */
TACCR1 = TAR + 1000;
if(ret == ELFLOADER_OK) {
sprintf(msg, "ok\n");
PRINTF("Ok, starting new program.\n");
/* Start processes. */
autostart_start(elfloader_autostart_processes);
} else {
sprintf(msg, "err %d %s", ret, elfloader_unknown);
PRINTF("Error: '%s'.\n", msg);
}
cfs_close(s.fd);
return ret;
}
/*---------------------------------------------------------------------*/
static
PT_THREAD(recv_tcpthread(struct pt *pt))
{
PT_BEGIN(pt);
/* Read the header. */
PT_WAIT_UNTIL(pt, uip_newdata() && uip_datalen() > 0);
if(uip_datalen() < sizeof(struct codeprop_tcphdr)) {
PRINTF(("codeprop: header not found in first tcp segment\n"));
uip_abort();
goto thread_done;
}
/* Kill old program. */
rudolph0_stop(&rudolph0);
/* elfloader_unload();*/
s.len = uip_htons(((struct codeprop_tcphdr *)uip_appdata)->len);
s.addr = 0;
uip_appdata += sizeof(struct codeprop_tcphdr);
uip_len -= sizeof(struct codeprop_tcphdr);
s.fd = cfs_open("codeprop.out", CFS_WRITE);
cfs_close(s.fd);
/* xmem_erase(XMEM_ERASE_UNIT_SIZE, EEPROMFS_ADDR_CODEPROP);*/
/* Read the rest of the data. */
do {
leds_toggle(LEDS_RED);
if(uip_len > 0) {
s.fd = cfs_open("codeprop.out", CFS_WRITE + CFS_APPEND);
cfs_seek(s.fd, s.addr, CFS_SEEK_SET);
/* xmem_pwrite(uip_appdata, uip_len, EEPROMFS_ADDR_CODEPROP + s.addr);*/
cfs_write(s.fd, uip_appdata, uip_len);
cfs_close(s.fd);
PRINTF("Wrote %d bytes to file\n", uip_len);
s.addr += uip_len;
}
if(s.addr < s.len) {
PT_YIELD_UNTIL(pt, uip_newdata());
}
} while(s.addr < s.len);
leds_off(LEDS_RED);
#if DEBUG
{
int i, fd, j;
printf("Contents of file:\n");
fd = cfs_open("codeprop.out", CFS_READ);
j = 0;
printf("\n0x%04x: ", 0);
for(i = 0; i < s.len; ++i) {
unsigned char byte;
cfs_read(fd, &byte, 1);
printf("0x%02x, ", byte);
++j;
if(j == 8) {
printf("\n0x%04x: ", i + 1);
j = 0;
}
clock_delay(400);
}
cfs_close(fd);
}
#endif
int ret;
ret = start_program();
#if CONTIKI_TARGET_NETSIM
rudolph0_send(&rudolph0, CLOCK_SECOND / 4);
#else /* CONTIKI_TARGET_NETSIM */
if(ret == ELFLOADER_OK) {
/* Propagate program. */
rudolph0_send(&rudolph0, CLOCK_SECOND / 4);
}
#endif /* CONTIKI_TARGET_NETSIM */
/* Return "ok" message. */
do {
ret = strlen(msg);
uip_send(msg, ret);
PT_WAIT_UNTIL(pt, uip_acked() || uip_rexmit() || uip_closed());
} while(uip_rexmit());
/* Close the connection. */
uip_close();
thread_done:;
PT_END(pt);
}
/*---------------------------------------------------------------------*/
static void
write_chunk(struct rudolph0_conn *c, int offset, int flag,
uint8_t *data, int datalen)
{
int fd;
leds_toggle(LEDS_YELLOW);
if(flag == RUDOLPH0_FLAG_NEWFILE) {
printf("+++ rudolph0 new file incoming at %u\n", clock_time());
fd = cfs_open("codeprop.out", CFS_WRITE);
if(elfloader_autostart_processes != NULL) {
PRINTF("Stopping old programs.\n");
autostart_exit(elfloader_autostart_processes);
elfloader_autostart_processes = NULL;
}
} else {
fd = cfs_open("codeprop.out", CFS_WRITE + CFS_APPEND);
}
if(datalen > 0) {
int ret;
cfs_seek(fd, offset, CFS_SEEK_SET);
ret = cfs_write(fd, data, datalen);
/* printf("write_chunk wrote %d bytes at %d, %d\n", ret, offset, (unsigned char)data[0]);*/
}
cfs_close(fd);
if(flag == RUDOLPH0_FLAG_LASTCHUNK) {
printf("+++ rudolph0 entire file received at %u\n", clock_time());
start_program();
leds_off(LEDS_YELLOW);
}
}
static int
read_chunk(struct rudolph0_conn *c, int offset, uint8_t *to, int maxsize)
{
int fd;
int ret;
leds_toggle(LEDS_GREEN);
fd = cfs_open("codeprop.out", CFS_READ);
cfs_seek(fd, offset, CFS_SEEK_SET);
ret = cfs_read(fd, to, maxsize);
/* printf("read_chunk %d bytes at %d, %d\n", ret, offset, (unsigned char)to[0]);*/
if(ret < maxsize) {
leds_off(LEDS_GREEN);
}
cfs_close(fd);
return ret;
}
const static struct rudolph0_callbacks rudolph0_call = {write_chunk,
read_chunk};
/*---------------------------------------------------------------------*/
PROCESS_THREAD(tcp_loader_process, ev, data)
{
PROCESS_BEGIN();
rudolph0_open(&rudolph0, 20, &rudolph0_call);
tcp_listen(UIP_HTONS(CODEPROP_DATA_PORT));
while(1) {
PROCESS_YIELD();
if(ev == tcpip_event && uip_conn->lport == UIP_HTONS(CODEPROP_DATA_PORT)) {
if(uip_connected()) { /* Really uip_connecting()!!! */
if(data == NULL) {
PT_INIT(&s.tcpthread_pt);
process_poll(&tcp_loader_process);
tcp_markconn(uip_conn, &s);
if(elfloader_autostart_processes != NULL) {
PRINTF("Stopping old programs.\n");
autostart_exit(elfloader_autostart_processes);
elfloader_autostart_processes = NULL;
}
} else {
PRINTF(("codeprop: uip_connected() and data != NULL\n"));
uip_abort();
}
}
recv_tcpthread(&s.tcpthread_pt); /* Run thread */
if(uip_closed() || uip_aborted() || uip_timedout()) {
PRINTF(("codeprop: connection down\n"));
tcp_markconn(uip_conn, NULL);
}
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------*/
#include "net/rime/collect.h"
#include "net/rime/mesh.h"
#include "net/rime/rudolph0.h"
#include "net/rime/rudolph1.h"
void
dummy(void)
{
/* Make sure that all Rime modules are present in the core */
collect_close(NULL);
mesh_close(NULL);
ipolite_close(NULL);
polite_close(NULL);
ruc_close(NULL);
sibc_close(NULL);
rudolph0_close(NULL);
rudolph1_close(NULL);
/* Make sure psock is included */
psock_datalen(NULL);
}
/*---------------------------------------------------------------------*/

View file

@ -30,7 +30,6 @@ sky-shell-webserver/sky \
tcp-socket/minimal-net \ tcp-socket/minimal-net \
telnet-server/minimal-net \ telnet-server/minimal-net \
webserver/minimal-net \ webserver/minimal-net \
webserver-ipv6/exp5438 \
webserver-ipv6/eval-adf7xxxmb4z \ webserver-ipv6/eval-adf7xxxmb4z \
wget/minimal-net \ wget/minimal-net \
z1/z1 \ z1/z1 \