#include "contiki.h"
#include "dev/button-sensor.h"
#include "dev/leds.h"
#include <stdio.h>
#if CONTIKI_TARGET_NETSIM
#include "ether.h"
#include "node.h"
#endif
#define FILESIZE 2000
PROCESS(example_rudolph2_process,
"Rudolph2 example");
AUTOSTART_PROCESSES(&example_rudolph2_process);
static void
write_chunk(struct rudolph2_conn *c, int offset, int flag,
uint8_t *data, int datalen)
{
int fd;
#if CONTIKI_TARGET_NETSIM
{
char buf[100];
sprintf(buf, "%d%%", (100 * (offset + datalen)) / FILESIZE);
ether_set_text(buf);
}
#endif
if(flag == RUDOLPH2_FLAG_NEWFILE) {
printf(
"+++ rudolph2 new file incoming at %lu\n",
clock_time());
leds_on(LEDS_RED);
} else {
}
if(datalen > 0) {
int ret;
ret = cfs_write(fd, data, datalen);
printf("+++ rudolph2 offset %d, length %d\n", offset, datalen);
}
if(flag == RUDOLPH2_FLAG_LASTCHUNK) {
int i;
printf("+++ rudolph2 entire file received at %d, %d\n",
leds_off(LEDS_RED);
leds_on(LEDS_YELLOW);
for(i = 0; i < FILESIZE; ++i) {
unsigned char buf;
int r = cfs_read(fd, &buf, 1);
if (r != 1) {
printf("%d.%d: error: read failed at %d\n",
i);
break;
}
else if(buf != (unsigned char)i) {
printf("%d.%d: error: diff at %d, %d != %d\n",
i, (unsigned char)i, buf);
break;
}
}
#if CONTIKI_TARGET_NETSIM
ether_send_done();
#endif
}
}
static int
read_chunk(struct rudolph2_conn *c, int offset, uint8_t *to, int maxsize)
{
int fd;
int ret;
ret = cfs_read(fd, to, maxsize);
return ret;
}
const static struct rudolph2_callbacks rudolph2_call = {write_chunk,
read_chunk};
static struct rudolph2_conn rudolph2;
#include "node-id.h"
{
static int fd;
rudolph2_open(&rudolph2, 142, &rudolph2_call);
SENSORS_ACTIVATE(button_sensor);
{
int i;
printf("%d.%d: selected data source\n",
for(i = 0; i < FILESIZE; i++) {
unsigned char buf = i;
int w = cfs_write(fd, &buf, 1);
if (w != 1) {
printf("%d.%d: error: write failed at %d\n",
i);
break;
}
}
}
#if CONTIKI_TARGET_NETSIM
ether_send_done();
#endif
}
while(1) {
data == &button_sensor);
rudolph2_stop(&rudolph2);
}
}