2007-03-15 23:06:19 +01:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*
|
2007-11-17 19:01:00 +01:00
|
|
|
* $Id: test-rudolph0.c,v 1.6 2007/11/17 18:09:56 adamdunkels Exp $
|
2007-03-15 23:06:19 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
2007-03-20 13:21:17 +01:00
|
|
|
* Testing the rudolph0 code in Rime
|
2007-03-15 23:06:19 +01:00
|
|
|
* \author
|
|
|
|
* Adam Dunkels <adam@sics.se>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "contiki.h"
|
2007-11-17 19:01:00 +01:00
|
|
|
#include "cfs/cfs.h"
|
2007-03-25 14:10:29 +02:00
|
|
|
#include "net/rime/rudolph0.h"
|
2007-03-15 23:06:19 +01:00
|
|
|
|
|
|
|
#include "dev/button-sensor.h"
|
|
|
|
|
|
|
|
#include "dev/leds.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2007-04-02 12:04:37 +02:00
|
|
|
|
|
|
|
#define FILESIZE 200
|
|
|
|
|
2007-03-15 23:06:19 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-03-22 00:24:24 +01:00
|
|
|
PROCESS(test_rudolph0_process, "Rudolph0 test");
|
2007-03-20 13:21:17 +01:00
|
|
|
AUTOSTART_PROCESSES(&test_rudolph0_process);
|
2007-03-15 23:06:19 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2007-03-23 00:54:40 +01:00
|
|
|
write_chunk(struct rudolph0_conn *c, int offset, int flag,
|
2007-11-17 19:01:00 +01:00
|
|
|
uint8_t *data, int datalen)
|
2007-03-15 23:06:19 +01:00
|
|
|
{
|
2007-03-20 13:21:17 +01:00
|
|
|
int fd;
|
|
|
|
|
2007-03-23 00:54:40 +01:00
|
|
|
if(flag == RUDOLPH0_FLAG_NEWFILE) {
|
2007-04-02 12:04:37 +02:00
|
|
|
/* printf("+++ rudolph0 new file incoming at %lu\n", clock_time());*/
|
|
|
|
leds_on(LEDS_RED);
|
2007-03-23 00:54:40 +01:00
|
|
|
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);
|
|
|
|
ret = cfs_write(fd, data, datalen);
|
2007-04-02 12:04:37 +02:00
|
|
|
/* printf("write_chunk wrote %d bytes at %d, %d\n", ret, offset, (unsigned char)data[0]);*/
|
2007-03-23 00:54:40 +01:00
|
|
|
}
|
2007-03-15 23:06:19 +01:00
|
|
|
|
2007-03-23 00:54:40 +01:00
|
|
|
cfs_close(fd);
|
|
|
|
|
|
|
|
if(flag == RUDOLPH0_FLAG_LASTCHUNK) {
|
|
|
|
int i;
|
2007-04-02 12:04:37 +02:00
|
|
|
/* printf("+++ rudolph0 entire file received at %lu\n", clock_time());*/
|
|
|
|
leds_off(LEDS_RED);
|
|
|
|
leds_on(LEDS_YELLOW);
|
2007-03-23 00:54:40 +01:00
|
|
|
fd = cfs_open("hej", CFS_READ);
|
2007-04-02 12:04:37 +02:00
|
|
|
for(i = 0; i < FILESIZE; ++i) {
|
2007-03-23 00:54:40 +01:00
|
|
|
unsigned char buf;
|
|
|
|
cfs_read(fd, &buf, 1);
|
2007-04-02 12:04:37 +02:00
|
|
|
if(buf != (unsigned char)i) {
|
2007-03-23 00:54:40 +01:00
|
|
|
printf("error: diff at %d, %d != %d\n", i, i, buf);
|
|
|
|
break;
|
|
|
|
}
|
2007-03-20 13:21:17 +01:00
|
|
|
}
|
2007-03-23 00:54:40 +01:00
|
|
|
cfs_close(fd);
|
2007-03-20 13:21:17 +01:00
|
|
|
}
|
2007-03-23 00:54:40 +01:00
|
|
|
}
|
|
|
|
static int
|
2007-11-17 19:01:00 +01:00
|
|
|
read_chunk(struct rudolph0_conn *c, int offset, uint8_t *to, int maxsize)
|
2007-03-23 00:54:40 +01:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
fd = cfs_open("hej", CFS_READ);
|
|
|
|
|
|
|
|
cfs_seek(fd, offset);
|
|
|
|
ret = cfs_read(fd, to, maxsize);
|
2007-04-02 12:04:37 +02:00
|
|
|
/* printf("read_chunk %d bytes at %d, %d\n", ret, offset, (unsigned char)to[0]);*/
|
2007-03-22 00:24:24 +01:00
|
|
|
cfs_close(fd);
|
2007-03-23 00:54:40 +01:00
|
|
|
return ret;
|
2007-03-15 23:06:19 +01:00
|
|
|
}
|
2007-03-23 00:54:40 +01:00
|
|
|
const static struct rudolph0_callbacks rudolph0_call = {write_chunk,
|
|
|
|
read_chunk};
|
2007-03-20 13:21:17 +01:00
|
|
|
static struct rudolph0_conn rudolph0;
|
2007-03-15 23:06:19 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-03-20 13:21:17 +01:00
|
|
|
PROCESS_THREAD(test_rudolph0_process, ev, data)
|
2007-03-15 23:06:19 +01:00
|
|
|
{
|
2007-03-22 00:24:24 +01:00
|
|
|
static int fd;
|
2007-03-25 14:10:29 +02:00
|
|
|
|
|
|
|
PROCESS_EXITHANDLER(rudolph0_close(&rudolph0);)
|
|
|
|
|
2007-03-15 23:06:19 +01:00
|
|
|
PROCESS_BEGIN();
|
|
|
|
|
2007-03-20 13:21:17 +01:00
|
|
|
PROCESS_PAUSE();
|
2007-03-15 23:06:19 +01:00
|
|
|
|
2007-03-20 13:21:17 +01:00
|
|
|
|
|
|
|
rudolph0_open(&rudolph0, 128, &rudolph0_call);
|
2007-03-15 23:06:19 +01:00
|
|
|
button_sensor.activate();
|
|
|
|
|
|
|
|
while(1) {
|
2007-03-20 13:21:17 +01:00
|
|
|
PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event &&
|
|
|
|
data == &button_sensor);
|
2007-04-02 12:04:37 +02:00
|
|
|
{
|
|
|
|
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);
|
2007-03-23 00:54:40 +01:00
|
|
|
|
|
|
|
PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event &&
|
|
|
|
data == &button_sensor);
|
|
|
|
rudolph0_stop(&rudolph0);
|
2007-03-15 23:06:19 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
PROCESS_END();
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|