Removed packetbuf references. This was a feature that is not used anymore and only made the code more complex.
This commit is contained in:
parent
c9c6688524
commit
7acf747c1a
|
@ -9,7 +9,7 @@ shell_src = shell.c shell-reboot.c shell-vars.c shell-ps.c \
|
|||
shell_dsc = shell-dsc.c
|
||||
|
||||
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-debug.c shell-rime-debug-runicast.c \
|
||||
shell-rime-sendcmd.c shell-download.c shell-rime-neighbors.c \
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -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_ */
|
|
@ -382,7 +382,6 @@ struct shell_input {
|
|||
#include "shell-httpd.h"
|
||||
#include "shell-irc.h"
|
||||
#include "shell-memdebug.h"
|
||||
#include "shell-netfile.h"
|
||||
#include "shell-netperf.h"
|
||||
#include "shell-netstat.h"
|
||||
#include "shell-ping.h"
|
||||
|
|
|
@ -106,10 +106,7 @@ packetbuf_compact(void)
|
|||
{
|
||||
int i, len;
|
||||
|
||||
if(packetbuf_is_reference()) {
|
||||
memcpy(&packetbuf[PACKETBUF_HDR_SIZE], packetbuf_reference_ptr(),
|
||||
packetbuf_datalen());
|
||||
} else if(bufptr > 0) {
|
||||
if(bufptr > 0) {
|
||||
len = packetbuf_datalen() + PACKETBUF_HDR_SIZE;
|
||||
for(i = PACKETBUF_HDR_SIZE; i < len; i++) {
|
||||
packetbuf[i] = packetbuf[bufptr + i];
|
||||
|
@ -215,26 +212,6 @@ packetbuf_hdrptr(void)
|
|||
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
|
||||
packetbuf_datalen(void)
|
||||
{
|
||||
|
|
|
@ -181,52 +181,12 @@ uint16_t packetbuf_totlen(void);
|
|||
*/
|
||||
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
|
||||
*
|
||||
* This function compacts the packetbuf by copying the data
|
||||
* portion of the packetbuf so that becomes consecutive to
|
||||
* the header. It also copies external data that has
|
||||
* previously been referenced with packetbuf_reference()
|
||||
* into the packetbuf.
|
||||
* the header.
|
||||
*
|
||||
* This function is called by the Rime code before a
|
||||
* 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
|
||||
* buffer. Both the data portion and the header portion of
|
||||
* the packetbuf is copied. If the packetbuf referenced
|
||||
* external data (referenced with packetbuf_reference()) the
|
||||
* external data is copied.
|
||||
* the packetbuf is copied.
|
||||
*
|
||||
* The external buffer to which the packetbuf is to be
|
||||
* copied must be able to accomodate at least
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
|
@ -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_ */
|
||||
/** @} */
|
||||
/** @} */
|
||||
|
|
@ -11,7 +11,6 @@
|
|||
/** \example example-mesh.c */
|
||||
/** \example example-multihop.c */
|
||||
/** \example example-rucb.c */
|
||||
/** \example example-rudolph0.c */
|
||||
/** \example example-rudolph1.c */
|
||||
/** \example example-rudolph2.c */
|
||||
/** \example example-runicast.c */
|
||||
|
|
|
@ -66,7 +66,6 @@ PROCESS_THREAD(example_shell_process, ev, data)
|
|||
shell_file_init();
|
||||
shell_httpd_init();
|
||||
shell_irc_init();
|
||||
shell_netfile_init();
|
||||
/*shell_ping_init();*/ /* uIP ping */
|
||||
shell_power_init();
|
||||
/*shell_profile_init();*/
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
CONTIKI = ../..
|
||||
|
||||
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
|
||||
|
||||
CONTIKI_WITH_RIME = 1
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -58,7 +58,6 @@ PROCESS_THREAD(test_shell_process, ev, data)
|
|||
shell_coffee_init();
|
||||
shell_exec_init();
|
||||
shell_file_init();
|
||||
shell_netfile_init();
|
||||
shell_ps_init();
|
||||
shell_rime_init();
|
||||
shell_rime_netcmd_init();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
/*---------------------------------------------------------------------*/
|
Loading…
Reference in a new issue