Merge branch 'master' of ssh://contiki.git.sourceforge.net/gitroot/contiki/contiki

This commit is contained in:
Joakim Eriksson 2011-06-14 23:49:51 +02:00
commit 6a1469aeb2
13 changed files with 124 additions and 121 deletions

View file

@ -33,10 +33,10 @@
/**
* \file
* The Deluge protocol for data dissemination.
* An implementation of the Deluge protocol.
* (Hui and Culler: The dynamic behavior of a data
* dissemination protocol for network programming at scale,
* SenSys 2004)
* ACM SenSys 2004)
* \author
* Nicolas Tsiftes <nvt@sics.se>
*/
@ -67,11 +67,6 @@
#define PRINTF(...)
#endif
PROCESS(deluge_process, "Deluge process");
static void broadcast_recv(struct broadcast_conn *, const rimeaddr_t *);
static void unicast_recv(struct unicast_conn *, const rimeaddr_t *);
/* Implementation-specific variables. */
static struct broadcast_conn deluge_broadcast;
static struct unicast_conn deluge_uc;
@ -86,32 +81,25 @@ static unsigned r_interval;
static unsigned recv_adv;
static int broadcast_profile;
/* Deluge timers. */
static struct ctimer rx_timer;
static struct ctimer tx_timer;
static struct ctimer summary_timer;
static struct ctimer profile_timer;
static unsigned next_object_id;
/* Deluge objects will get an ID that defaults to the current value of
the next_object_id parameter. */
static deluge_object_id_t next_object_id;
/* Rime callbacks. */
static void broadcast_recv(struct broadcast_conn *, const rimeaddr_t *);
static void unicast_recv(struct unicast_conn *, const rimeaddr_t *);
static const struct broadcast_callbacks broadcast_call = {broadcast_recv, NULL};
static const struct unicast_callbacks unicast_call = {unicast_recv, NULL};
#if NETSIM
static char label[128];
#endif
static uint16_t
checksum(unsigned char *buf, unsigned len)
{
unsigned i;
uint16_t sum;
for(i = sum = 0; i < len; i++) {
sum = crc16_add(buf[i], sum);
}
return sum;
}
/* The Deluge process manages the main Deluge timer. */
PROCESS(deluge_process, "Deluge");
static void
transition(int state)
@ -136,15 +124,26 @@ transition(int state)
static int
write_page(struct deluge_object *obj, unsigned pagenum, unsigned char *data)
{
cfs_seek(obj->cfs_fd, pagenum * S_PAGE, CFS_SEEK_SET);
return cfs_write(obj->cfs_fd, (char *)data,
S_PAGE);
cfs_offset_t offset;
offset = pagenum * S_PAGE;
if(cfs_seek(obj->cfs_fd, offset, CFS_SEEK_SET) != offset) {
return -1;
}
return cfs_write(obj->cfs_fd, (char *)data, S_PAGE);
}
static int
read_page(struct deluge_object *obj, unsigned pagenum, unsigned char *buf)
{
cfs_seek(obj->cfs_fd, pagenum * S_PAGE, CFS_SEEK_SET);
cfs_offset_t offset;
offset = pagenum * S_PAGE;
if(cfs_seek(obj->cfs_fd, offset, CFS_SEEK_SET) != offset) {
return -1;
}
return cfs_read(obj->cfs_fd, (char *)buf, S_PAGE);
}
@ -165,26 +164,27 @@ init_page(struct deluge_object *obj, int pagenum, int have)
page->packet_set = ALL_PACKETS;
page->flags |= PAGE_COMPLETE;
read_page(obj, pagenum, buf);
page->crc = checksum(buf, S_PAGE);
page->crc = crc16_data(buf, S_PAGE, 0);
} else {
page->version = 0;
page->packet_set = 0;
}
}
static int
static cfs_offset_t
file_size(const char *file)
{
int fd, size;
int fd;
cfs_offset_t size;
fd = cfs_open(file, CFS_READ);
if(fd < 0) {
return -1;
return (cfs_offset_t)-1;
}
size = cfs_seek(fd, 0, CFS_SEEK_END);
cfs_close(fd);
return size;
}
@ -209,6 +209,7 @@ init_object(struct deluge_object *obj, char *filename, unsigned version)
obj->pages = malloc(OBJECT_PAGE_COUNT(*obj) * sizeof(*obj->pages));
if(obj->pages == NULL) {
cfs_close(obj->cfs_fd);
return -1;
}
@ -217,7 +218,7 @@ init_object(struct deluge_object *obj, char *filename, unsigned version)
init_page(&current_object, i, 1);
}
memset(obj->current_page, 0, sizeof (obj->current_page));
memset(obj->current_page, 0, sizeof(obj->current_page));
return 0;
}
@ -244,15 +245,15 @@ send_request(void *arg)
obj = (struct deluge_object *)arg;
request.object_id = obj->object_id;
request.cmd = DELUGE_CMD_REQUEST;
request.pagenum = obj->current_rx_page;
request.version = obj->pages[request.pagenum].version;
request.request_set = ~obj->pages[obj->current_rx_page].packet_set;
request.object_id = obj->object_id;
PRINTF("Sending request for page %d, version %u, request_set %u\n",
request.pagenum, request.version, request.request_set);
packetbuf_copyfrom((uint8_t *)&request, sizeof (request));
packetbuf_copyfrom(&request, sizeof(request));
unicast_send(&deluge_uc, &obj->summary_from);
/* Deluge R.2 */
@ -276,14 +277,14 @@ advertise_summary(struct deluge_object *obj)
}
summary.cmd = DELUGE_CMD_SUMMARY;
summary.object_id = obj->object_id;
summary.version = obj->update_version;
summary.highest_available = highest_available_page(obj);
summary.object_id = obj->object_id;
PRINTF("Advertising summary for object id %u: version=%u, available=%u\n",
(unsigned) obj->object_id, summary.version, summary.highest_available);
(unsigned)obj->object_id, summary.version, summary.highest_available);
packetbuf_copyfrom((uint8_t *)&summary, sizeof (summary));
packetbuf_copyfrom(&summary, sizeof(summary));
broadcast_send(&deluge_broadcast);
}
@ -351,10 +352,10 @@ send_page(struct deluge_object *obj, unsigned pagenum)
unsigned char *cp;
pkt.cmd = DELUGE_CMD_PACKET;
pkt.object_id = obj->object_id;
pkt.pagenum = pagenum;
pkt.version = obj->pages[pagenum].version;
pkt.packetnum = 0;
pkt.object_id = obj->object_id;
pkt.crc = 0;
read_page(obj, pagenum, buf);
@ -362,9 +363,9 @@ send_page(struct deluge_object *obj, unsigned pagenum)
/* Divide the page into packets and send them one at a time. */
for(cp = buf; cp + S_PKT <= (unsigned char *)&buf[S_PAGE]; cp += S_PKT) {
if(obj->tx_set & (1 << pkt.packetnum)) {
pkt.crc = checksum(cp, S_PKT);
pkt.crc = crc16_data(cp, S_PKT, 0);
memcpy(pkt.payload, cp, S_PKT);
packetbuf_copyfrom((uint8_t *)&pkt, sizeof (pkt));
packetbuf_copyfrom(&pkt, sizeof(pkt));
broadcast_send(&deluge_broadcast);
}
pkt.packetnum++;
@ -382,8 +383,12 @@ tx_callback(void *arg)
send_page(obj, obj->current_tx_page);
/* Deluge T.2. */
if(obj->tx_set) {
packetbuf_set_attr(PACKETBUF_ATTR_PACKET_TYPE,
PACKETBUF_ATTR_PACKET_TYPE_STREAM);
ctimer_reset(&tx_timer);
} else {
packetbuf_set_attr(PACKETBUF_ATTR_PACKET_TYPE,
PACKETBUF_ATTR_PACKET_TYPE_STREAM_END);
obj->current_tx_page = -1;
transition(DELUGE_STATE_MAINTAIN);
}
@ -449,7 +454,7 @@ handle_packet(struct deluge_msg_packet *msg)
memcpy(&current_object.current_page[S_PKT * packet.packetnum],
packet.payload, S_PKT);
crc = checksum(packet.payload, S_PKT);
crc = crc16_data(packet.payload, S_PKT, 0);
if(packet.crc != crc) {
PRINTF("packet crc: %hu, calculated crc: %hu\n", packet.crc, crc);
return;
@ -459,6 +464,10 @@ handle_packet(struct deluge_msg_packet *msg)
page->packet_set |= (1 << packet.packetnum);
if(page->packet_set == ALL_PACKETS) {
/* This is the last packet of the requested page; stop streaming. */
packetbuf_set_attr(PACKETBUF_ATTR_PACKET_TYPE,
PACKETBUF_ATTR_PACKET_TYPE_STREAM_END);
write_page(&current_object, packet.pagenum, current_object.current_page);
page->version = packet.version;
page->flags = PAGE_COMPLETE;
@ -470,7 +479,7 @@ handle_packet(struct deluge_msg_packet *msg)
current_object.version = current_object.update_version;
leds_on(LEDS_RED);
PRINTF("Update completed for object %u, version %u\n",
current_object.object_id, packet.version);
(unsigned)current_object.object_id, packet.version);
} else if(current_object.current_rx_page < OBJECT_PAGE_COUNT(current_object)) {
if(ctimer_expired(&rx_timer)) {
ctimer_set(&rx_timer,
@ -480,36 +489,19 @@ handle_packet(struct deluge_msg_packet *msg)
}
/* Deluge R.3 */
transition(DELUGE_STATE_MAINTAIN);
} else {
/* More packets to come. Put lower layers in streaming mode. */
packetbuf_set_attr(PACKETBUF_ATTR_PACKET_TYPE,
PACKETBUF_ATTR_PACKET_TYPE_STREAM);
}
}
}
static void
unicast_recv(struct unicast_conn *c, const rimeaddr_t *sender)
{
char *msg;
int len;
msg = packetbuf_dataptr();
len = packetbuf_datalen();
if(len < 5)
return;
switch(msg[2]) {
case DELUGE_CMD_REQUEST:
if(len >= sizeof (struct deluge_msg_request))
handle_request((struct deluge_msg_request *)msg);
break;
default:
PRINTF("Incoming packet with unknown command!\n");
}
}
static void
send_profile(struct deluge_object *obj)
{
struct deluge_msg_profile *msg;
unsigned char buf[sizeof (*msg) + OBJECT_PAGE_COUNT(*obj)];
unsigned char buf[sizeof(*msg) + OBJECT_PAGE_COUNT(*obj)];
int i;
if(broadcast_profile && recv_adv < CONST_K) {
@ -517,14 +509,14 @@ send_profile(struct deluge_object *obj)
msg = (struct deluge_msg_profile *)buf;
msg->cmd = DELUGE_CMD_PROFILE;
msg->object_id = obj->object_id;
msg->version = obj->version;
msg->npages = OBJECT_PAGE_COUNT(*obj);
msg->object_id = obj->object_id;
for(i = 0; i < msg->npages; i++) {
msg->version_vector[i] = obj->pages[i].version;
}
packetbuf_copyfrom(buf, sizeof (buf));
packetbuf_copyfrom(buf, sizeof(buf));
broadcast_send(&deluge_broadcast);
}
}
@ -551,13 +543,13 @@ handle_profile(struct deluge_msg_profile *msg)
npages = OBJECT_PAGE_COUNT(*obj);
obj->size = msg->npages * S_PAGE;
p = malloc(OBJECT_PAGE_COUNT(*obj) * sizeof (*obj->pages));
p = malloc(OBJECT_PAGE_COUNT(*obj) * sizeof(*obj->pages));
if(p == NULL) {
PRINTF("Failed to reallocate memory for pages!\n");
return;
}
memcpy(p, obj->pages, npages * sizeof (*obj->pages));
memcpy(p, obj->pages, npages * sizeof(*obj->pages));
free(obj->pages);
obj->pages = (struct deluge_page *)p;
@ -588,7 +580,7 @@ handle_profile(struct deluge_msg_profile *msg)
}
static void
broadcast_recv(struct broadcast_conn *c, const rimeaddr_t *sender)
command_dispatcher(const rimeaddr_t *sender)
{
char *msg;
int len;
@ -596,37 +588,50 @@ broadcast_recv(struct broadcast_conn *c, const rimeaddr_t *sender)
msg = packetbuf_dataptr();
len = packetbuf_datalen();
if(len < 5)
if(len < 1)
return;
switch(msg[2]) {
switch(msg[0]) {
case DELUGE_CMD_SUMMARY:
if(len >= sizeof (struct deluge_msg_summary))
if(len >= sizeof(struct deluge_msg_summary))
handle_summary((struct deluge_msg_summary *)msg, sender);
break;
case DELUGE_CMD_REQUEST:
if(len >= sizeof (struct deluge_msg_request))
if(len >= sizeof(struct deluge_msg_request))
handle_request((struct deluge_msg_request *)msg);
break;
case DELUGE_CMD_PACKET:
if(len >= sizeof (struct deluge_msg_packet))
if(len >= sizeof(struct deluge_msg_packet))
handle_packet((struct deluge_msg_packet *)msg);
break;
case DELUGE_CMD_PROFILE:
profile = (struct deluge_msg_profile *)msg;
if(len >= sizeof (*profile) &&
len >= sizeof (*profile) + profile->npages * profile->version_vector[0])
if(len >= sizeof(*profile) &&
len >= sizeof(*profile) + profile->npages * profile->version_vector[0])
handle_profile((struct deluge_msg_profile *)msg);
break;
default:
PRINTF("Incoming packet with unknown command!\n");
PRINTF("Incoming packet with unknown command: %d\n", msg[0]);
}
}
static void
unicast_recv(struct unicast_conn *c, const rimeaddr_t *sender)
{
command_dispatcher(sender);
}
static void
broadcast_recv(struct broadcast_conn *c, const rimeaddr_t *sender)
{
command_dispatcher(sender);
}
int
deluge_disseminate(char *file, unsigned version)
{
if(init_object(&current_object, file, version) < 0) {
/* This implementation disseminates at most one object. */
if(next_object_id > 0 || init_object(&current_object, file, version) < 0) {
return -1;
}
process_start(&deluge_process, file);

View file

@ -95,38 +95,40 @@ PROCESS_NAME(deluge_process);
#define CONST_OMEGA 8
#define ESTIMATED_TX_TIME (CLOCK_SECOND)
typedef uint8_t deluge_object_id_t;
struct deluge_msg_summary {
uint16_t object_id;
uint8_t cmd;
uint8_t version;
uint8_t highest_available;
} __attribute__((packed));
deluge_object_id_t object_id;
};
struct deluge_msg_request {
uint16_t object_id;
uint8_t cmd;
uint8_t version;
uint8_t pagenum;
uint8_t request_set;
} __attribute__((packed));
deluge_object_id_t object_id;
};
struct deluge_msg_packet {
uint16_t object_id;
uint8_t cmd;
uint8_t version;
uint8_t pagenum;
uint8_t packetnum;
uint16_t crc;
deluge_object_id_t object_id;
unsigned char payload[S_PKT];
} __attribute__((packed));
};
struct deluge_msg_profile {
uint16_t object_id;
uint8_t cmd;
uint8_t version;
uint8_t npages;
deluge_object_id_t object_id;
uint8_t version_vector[];
} __attribute__((packed));
};
struct deluge_object {
char *filename;

View file

@ -799,7 +799,6 @@ create_log(struct file *file, struct file_header *hdr)
static int
merge_log(coffee_page_t file_page, int extend)
{
coffee_page_t log_page;
struct file_header hdr, hdr2;
int fd, n;
cfs_offset_t offset;
@ -808,7 +807,6 @@ merge_log(coffee_page_t file_page, int extend)
int i;
read_header(&hdr, file_page);
log_page = hdr.log_page;
fd = cfs_open(hdr.name, CFS_READ);
if(fd < 0) {

View file

@ -56,7 +56,7 @@
#define PRINTF(...)
#endif
#ifndef SDA_0()
#ifndef SDA_0
#define SDA_0() (SHT11_PxDIR |= BV(SHT11_ARCH_SDA)) /* SDA Output=0 */
#define SDA_1() (SHT11_PxDIR &= ~BV(SHT11_ARCH_SDA)) /* SDA Input */
#define SDA_IS_1 (SHT11_PxIN & BV(SHT11_ARCH_SDA))
@ -72,7 +72,7 @@
#define RESET 0x1e /* 000 1111 0 */
/* This can probably be reduced to 250ns according to data sheet. */
#ifndef delay_400ns()
#ifndef delay_400ns
#define delay_400ns() _NOP()
#endif
/*---------------------------------------------------------------------------*/
@ -217,7 +217,7 @@ sht11_init(void)
* SDA 0: Output=0
* 1: Input and pull-up (Output=0)
*/
#ifdef SHT11_INIT()
#ifdef SHT11_INIT
SHT11_INIT();
#else
SHT11_PxOUT |= BV(SHT11_ARCH_PWR);
@ -232,7 +232,7 @@ sht11_init(void)
void
sht11_off(void)
{
#ifdef SHT11_OFF()
#ifdef SHT11_OFF
SHT11_OFF();
#else
SHT11_PxOUT &= ~BV(SHT11_ARCH_PWR);

View file

@ -1452,6 +1452,7 @@ collect_send(struct collect_conn *tc, int rexmits)
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
printf("%d.%d: drop originated packet: no queuebuf\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
ret = 0;
}

View file

@ -267,4 +267,9 @@ unsigned long clock_seconds(void);
#define CCIF
#define CLIF
/* include the project config */
/* PROJECT_CONF_H might be defined in the project Makefile */
#ifdef PROJECT_CONF_H
#include PROJECT_CONF_H
#endif /* PROJECT_CONF_H */
#endif /* __CONTIKI_CONF_H__ */

View file

@ -261,4 +261,10 @@ unsigned long clock_seconds(void);
#define CCIF
#define CLIF
/* include the project config */
/* PROJECT_CONF_H might be defined in the project Makefile */
#ifdef PROJECT_CONF_H
#include PROJECT_CONF_H
#endif /* PROJECT_CONF_H */
#endif /* __CONTIKI_CONF_H__ */

View file

@ -384,8 +384,8 @@ extern void mac_log_802_15_4_rx(const uint8_t* buffer, size_t total_len);
#define UIP_CONF_MAX_LISTENPORTS 2
#define UIP_CONF_UDP_CONNS 6
/* Optional, TCP needed to serve the RPL neighbor web page currently hard coded at bbbb::11 */
/* The RPL neighbors can also be viewed using the jack menu */
/* Optional, TCP needed to serve the RPL neighbor web page currently hard coded at bbbb::200 */
/* The RPL neighbors can also be viewed using the jackdaw menu */
/* A small MSS is adequate for the internal jackdaw webserver and RAM is very limited*/
#define RPL_HTTPD_SERVER 0
#if RPL_HTTPD_SERVER

View file

@ -51,11 +51,11 @@ Berlin, 2007
* ScatterWeb Bootload and Contiki.
*/
#include "contiki.h"
#include <io.h>
#include <signal.h>
#include <string.h>
#include "dev/msb430-uart1.h"
#include "msp430.h"
#include "dev/lpm.h"
#ifndef U1ME

View file

@ -46,6 +46,7 @@ import se.sics.cooja.mspmote.MspMoteTimeEvent;
import se.sics.mspsim.core.IOUnit;
import se.sics.mspsim.core.USART;
import se.sics.mspsim.core.USARTListener;
import se.sics.mspsim.core.USARTSource;
/**
* @author Fredrik Osterlind
@ -73,13 +74,9 @@ public class MspSerial extends SerialUI implements SerialPort {
if (ioUnit instanceof USART) {
usart = (USART) ioUnit;
usart.setUSARTListener(new USARTListener() {
public void dataReceived(USART arg0, int arg1) {
MspSerial.this.dataReceived(arg1);
}
public void stateChanged(int state) {
if (state == USARTListener.RXFLAG_CLEARED) {
/*tryWriteNextByte();*/
}
@Override
public void dataReceived(USARTSource source, int data) {
MspSerial.this.dataReceived(data);
}
});
}

View file

@ -31,18 +31,8 @@
package se.sics.cooja.mspmote.interfaces;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.apache.log4j.Logger;
import org.jdom.Element;
@ -62,6 +52,7 @@ import se.sics.cooja.mspmote.MspMoteTimeEvent;
import se.sics.mspsim.core.IOUnit;
import se.sics.mspsim.core.USART;
import se.sics.mspsim.core.USARTListener;
import se.sics.mspsim.core.USARTSource;
/**
* TR1001 radio interface on ESB platform.
@ -200,7 +191,7 @@ public class TR1001Radio extends Radio implements USARTListener, CustomDataRadio
}
/* USART listener support */
public void dataReceived(USART source, int data) {
public void dataReceived(USARTSource source, int data) {
if (!isTransmitting()) {
/* New transmission discovered */
/*logger.info("----- NEW TR1001 TRANSMISSION DETECTED -----");*/
@ -253,9 +244,6 @@ public class TR1001Radio extends Radio implements USARTListener, CustomDataRadio
}
}
public void stateChanged(int state) {
}
/* General radio support */
public boolean isTransmitting() {
return isTransmitting;

Binary file not shown.

View file

@ -8,7 +8,8 @@
# contikichecker
#start the nodegui service
service controlgui start
service nodegui start
#service stackchart start
service -f controlgui start
service -f nodegui start
service -f serialgui start
#service -f stackchart start
start