#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_rudolph1_process,
"Rudolph1 example");
AUTOSTART_PROCESSES(&example_rudolph1_process);
static void
write_chunk(struct rudolph1_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 == RUDOLPH1_FLAG_NEWFILE) {
leds_on(LEDS_RED);
} else {
}
if(datalen > 0) {
int ret;
ret = cfs_write(fd, data, datalen);
}
if(flag == RUDOLPH1_FLAG_LASTCHUNK) {
int i;
printf("+++ rudolph1 entire file received at %d, %d\n",
leds_off(LEDS_RED);
leds_on(LEDS_YELLOW);
for(i = 0; i < FILESIZE; ++i) {
unsigned char buf;
cfs_read(fd, &buf, 1);
if(buf != (unsigned char)i) {
printf("%d.%d: error: diff at %d, %d != %d\n",
i, i, buf);
break;
}
}
#if CONTIKI_TARGET_NETSIM
ether_send_done();
#endif
}
}
static int
read_chunk(struct rudolph1_conn *c, int offset, uint8_t *to, int maxsize)
{
int fd;
int ret;
ret = cfs_read(fd, to, maxsize);
return ret;
}
const static struct rudolph1_callbacks rudolph1_call = {write_chunk,
read_chunk};
static struct rudolph1_conn rudolph1;
static void
log_queuelen(
struct rtimer *t,
void *ptr)
{
#if CONTIKI_TARGET_NETSIM
extern uint8_t queuebuf_len, queuebuf_ref_len;
node_log("%d %d\n",
queuebuf_len,
queuebuf_ref_len);
log_queuelen, ptr);
#endif
}
{
static int fd;
rudolph1_open(&rudolph1, 140, &rudolph1_call);
SENSORS_ACTIVATE(button_sensor);
{
int i;
for(i = 0; i < FILESIZE; i++) {
unsigned char buf = i;
cfs_write(fd, &buf, 1);
}
}
#if CONTIKI_TARGET_NETSIM
ether_send_done();
#endif
}
while(1) {
data == &button_sensor);
rudolph1_stop(&rudolph1);
}
}