Added LED output that shows when a file has been completely downloaded

This commit is contained in:
adamdunkels 2007-04-02 10:04:37 +00:00
parent 05692681a7
commit 2f50533d30
2 changed files with 71 additions and 37 deletions

View file

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: test-rudolph0.c,v 1.3 2007/03/25 12:10:29 adamdunkels Exp $
* $Id: test-rudolph0.c,v 1.4 2007/04/02 10:04:37 adamdunkels Exp $
*/
/**
@ -48,6 +48,9 @@
#include "cfs/cfs-ram.h"
#include <stdio.h>
#define FILESIZE 200
/*---------------------------------------------------------------------------*/
PROCESS(test_rudolph0_process, "Rudolph0 test");
AUTOSTART_PROCESSES(&test_rudolph0_process);
@ -59,7 +62,8 @@ write_chunk(struct rudolph0_conn *c, int offset, int flag,
int fd;
if(flag == RUDOLPH0_FLAG_NEWFILE) {
printf("+++ rudolph0 new file incoming at %lu\n", clock_time());
/* 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);
@ -69,20 +73,21 @@ write_chunk(struct rudolph0_conn *c, int offset, int flag,
int ret;
cfs_seek(fd, offset);
ret = cfs_write(fd, data, datalen);
printf("write_chunk wrote %d bytes at %d, %d\n", ret, offset, (unsigned char)data[0]);
/* 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());
/* 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 < 200; ++i) {
for(i = 0; i < FILESIZE; ++i) {
unsigned char buf;
cfs_read(fd, &buf, 1);
if(buf != i) {
if(buf != (unsigned char)i) {
printf("error: diff at %d, %d != %d\n", i, i, buf);
break;
}
@ -100,7 +105,7 @@ read_chunk(struct rudolph0_conn *c, int offset, char *to, int maxsize)
cfs_seek(fd, offset);
ret = cfs_read(fd, to, maxsize);
printf("read_chunk %d bytes at %d, %d\n", ret, offset, (unsigned char)to[0]);
/* printf("read_chunk %d bytes at %d, %d\n", ret, offset, (unsigned char)to[0]);*/
cfs_close(fd);
return ret;
}
@ -118,16 +123,6 @@ PROCESS_THREAD(test_rudolph0_process, ev, data)
PROCESS_PAUSE();
{
int i;
fd = cfs_open("hej", CFS_WRITE);
for(i = 0; i < 200; i++) {
unsigned char buf = i;
cfs_write(fd, &buf, 1);
}
cfs_close(fd);
}
rudolph0_open(&rudolph0, 128, &rudolph0_call);
button_sensor.activate();
@ -135,7 +130,17 @@ PROCESS_THREAD(test_rudolph0_process, ev, data)
while(1) {
PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event &&
data == &button_sensor);
rudolph0_send(&rudolph0);
{
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);

View file

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: test-rudolph1.c,v 1.3 2007/03/25 12:10:29 adamdunkels Exp $
* $Id: test-rudolph1.c,v 1.4 2007/04/02 10:04:37 adamdunkels Exp $
*/
/**
@ -48,6 +48,9 @@
#include "cfs/cfs-ram.h"
#include <stdio.h>
#define FILESIZE 200
/*---------------------------------------------------------------------------*/
PROCESS(test_rudolph1_process, "Rudolph1 test");
AUTOSTART_PROCESSES(&test_rudolph1_process);
@ -59,7 +62,8 @@ write_chunk(struct rudolph1_conn *c, int offset, int flag,
int fd;
if(flag == RUDOLPH1_FLAG_NEWFILE) {
printf("+++ rudolph1 new file incoming at %lu\n", clock_time());
/*printf("+++ rudolph1 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);
@ -69,24 +73,29 @@ write_chunk(struct rudolph1_conn *c, int offset, int flag,
int ret;
cfs_seek(fd, offset);
ret = cfs_write(fd, data, datalen);
printf("write_chunk wrote %d bytes at %d, %d\n", ret, offset, (unsigned char)data[0]);
/* printf("write_chunk wrote %d bytes at %d, %d\n", ret, offset, (unsigned char)data[0]);*/
}
cfs_close(fd);
if(flag == RUDOLPH1_FLAG_LASTCHUNK) {
int i;
printf("+++ rudolph1 entire file received at %lu\n", clock_time());
/* printf("+++ rudolph1 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 < 200; ++i) {
for(i = 0; i < FILESIZE; ++i) {
unsigned char buf;
cfs_read(fd, &buf, 1);
if(buf != i) {
if(buf != (unsigned char)i) {
printf("error: diff at %d, %d != %d\n", i, i, buf);
break;
}
}
#if NETSIM
ether_send_done();
#endif
cfs_close(fd);
}
}
@ -100,7 +109,7 @@ read_chunk(struct rudolph1_conn *c, int offset, char *to, int maxsize)
cfs_seek(fd, offset);
ret = cfs_read(fd, to, maxsize);
printf("read_chunk %d bytes at %d, %d\n", ret, offset, (unsigned char)to[0]);
/* printf("read_chunk %d bytes at %d, %d\n", ret, offset, (unsigned char)to[0]);*/
cfs_close(fd);
return ret;
}
@ -108,6 +117,8 @@ const static struct rudolph1_callbacks rudolph1_call = {write_chunk,
read_chunk};
static struct rudolph1_conn rudolph1;
/*---------------------------------------------------------------------------*/
#include "node-id.h"
PROCESS_THREAD(test_rudolph1_process, ev, data)
{
static int fd;
@ -116,24 +127,42 @@ PROCESS_THREAD(test_rudolph1_process, ev, data)
PROCESS_PAUSE();
rudolph1_open(&rudolph1, 128, &rudolph1_call);
button_sensor.activate();
PROCESS_PAUSE();
if(rimeaddr_node_addr.u8[0] == 1 &&
rimeaddr_node_addr.u8[1] == 1) {
{
int i;
fd = cfs_open("hej", CFS_WRITE);
for(i = 0; i < 200; i++) {
for(i = 0; i < FILESIZE; i++) {
unsigned char buf = i;
cfs_write(fd, &buf, 1);
}
cfs_close(fd);
}
rudolph1_send(&rudolph1, CLOCK_SECOND / 2);
rudolph1_open(&rudolph1, 128, &rudolph1_call);
button_sensor.activate();
}
while(1) {
PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event &&
data == &button_sensor);
rudolph1_send(&rudolph1);
{
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);
}
rudolph1_send(&rudolph1, CLOCK_SECOND / 2);
PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event &&
data == &button_sensor);