2006-06-18 00:41:10 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004, 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.
|
|
|
|
*
|
|
|
|
* Author: Adam Dunkels <adam@sics.se>
|
|
|
|
*
|
2007-05-20 23:41:31 +02:00
|
|
|
* $Id: contiki-main.c,v 1.15 2007/05/20 21:41:31 oliverschmidt Exp $
|
2006-06-18 00:41:10 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "contiki.h"
|
|
|
|
#include "contiki-net.h"
|
|
|
|
#include "contiki-lib.h"
|
2007-03-23 00:59:26 +01:00
|
|
|
|
2007-03-15 22:58:13 +01:00
|
|
|
#include "net/rime.h"
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2007-04-01 23:05:17 +02:00
|
|
|
#ifdef __CYGWIN__
|
2007-05-20 23:41:31 +02:00
|
|
|
#include "net/wpcap-drv.h"
|
2007-04-01 23:05:17 +02:00
|
|
|
#else
|
2007-05-20 23:41:31 +02:00
|
|
|
#include "net/tapdev-drv.h"
|
2007-04-01 23:05:17 +02:00
|
|
|
#endif
|
2007-03-14 01:32:30 +01:00
|
|
|
#include "net/ethernode-uip.h"
|
2007-03-13 14:07:47 +01:00
|
|
|
#include "net/ethernode-rime.h"
|
2006-06-18 00:41:10 +02:00
|
|
|
#include "net/ethernode.h"
|
2007-03-22 19:59:34 +01:00
|
|
|
#include "net/uip-over-mesh.h"
|
2007-03-15 22:58:13 +01:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
#include "ether.h"
|
|
|
|
|
|
|
|
/*#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>*/
|
|
|
|
|
|
|
|
#include "dev/button-sensor.h"
|
|
|
|
#include "dev/pir-sensor.h"
|
|
|
|
#include "dev/vib-sensor.h"
|
2006-10-06 10:25:30 +02:00
|
|
|
#include "dev/radio-sensor.h"
|
2006-06-18 00:41:10 +02:00
|
|
|
#include "dev/leds.h"
|
|
|
|
|
2007-04-01 23:05:17 +02:00
|
|
|
#ifdef __CYGWIN__
|
|
|
|
static struct uip_fw_netif extif =
|
|
|
|
{UIP_FW_NETIF(0,0,0,0, 0,0,0,0, wpcap_output)};
|
|
|
|
#else
|
|
|
|
static struct uip_fw_netif extif =
|
2007-03-30 00:24:47 +02:00
|
|
|
{UIP_FW_NETIF(0,0,0,0, 0,0,0,0, tapdev_output)};
|
2007-04-01 23:05:17 +02:00
|
|
|
#endif
|
2007-03-22 19:59:34 +01:00
|
|
|
static struct uip_fw_netif meshif =
|
|
|
|
{UIP_FW_NETIF(172,16,0,0, 255,255,0,0, uip_over_mesh_send)};
|
2007-03-14 01:32:30 +01:00
|
|
|
/*static struct uip_fw_netif ethernodeif =
|
|
|
|
{UIP_FW_NETIF(172,16,0,0, 255,255,0,0, ethernode_drv_send)};*/
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
static const struct uip_eth_addr ethaddr = {{0x00,0x06,0x98,0x01,0x02,0x12}};
|
|
|
|
|
2006-10-06 10:25:30 +02:00
|
|
|
SENSORS(&button_sensor, &pir_sensor, &vib_sensor, &radio_sensor);
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
PROCINIT(&sensors_process, &etimer_process, &tcpip_process,
|
2007-03-14 01:32:30 +01:00
|
|
|
/* ðernode_uip_process,*/
|
|
|
|
ðernode_rime_process,
|
2006-06-18 00:41:10 +02:00
|
|
|
&uip_fw_process);
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
contiki_main(int flag)
|
|
|
|
{
|
2006-10-23 11:01:06 +02:00
|
|
|
random_init(getpid());
|
2007-03-14 01:32:30 +01:00
|
|
|
srand(getpid());
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
leds_init();
|
|
|
|
|
|
|
|
process_init();
|
|
|
|
|
|
|
|
procinit_init();
|
2007-03-14 01:32:30 +01:00
|
|
|
|
2007-03-22 19:59:34 +01:00
|
|
|
uip_init();
|
|
|
|
|
2007-03-14 01:32:30 +01:00
|
|
|
rime_init();
|
2007-03-22 19:59:34 +01:00
|
|
|
uip_over_mesh_init(0);
|
2007-03-14 01:32:30 +01:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
if(flag == 1) {
|
2007-04-01 23:05:17 +02:00
|
|
|
#ifdef __CYGWIN__
|
|
|
|
process_start(&wpcap_process, NULL);
|
|
|
|
#else
|
2007-03-28 22:15:15 +02:00
|
|
|
process_start(&tapdev_process, NULL);
|
2007-04-01 23:05:17 +02:00
|
|
|
#endif
|
2007-03-22 19:59:34 +01:00
|
|
|
uip_fw_register(&meshif);
|
2007-04-01 23:05:17 +02:00
|
|
|
uip_fw_default(&extif);
|
2006-08-14 16:01:02 +02:00
|
|
|
printf("uip_hostaddr %02x%02x\n", uip_hostaddr.u16[0], uip_hostaddr.u16[1]);
|
2006-06-18 00:41:10 +02:00
|
|
|
} else {
|
2007-03-22 19:59:34 +01:00
|
|
|
uip_fw_default(&meshif);
|
2006-06-18 00:41:10 +02:00
|
|
|
}
|
2007-03-22 19:59:34 +01:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
leds_green(LEDS_ON);
|
|
|
|
|
|
|
|
autostart_start(autostart_processes);
|
2007-03-13 14:07:47 +01:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
while(1) {
|
|
|
|
int n;
|
|
|
|
n = process_run();
|
|
|
|
/* if(n > 0) {
|
|
|
|
printf("%d processes in queue\n");
|
|
|
|
}*/
|
|
|
|
usleep(1);
|
|
|
|
etimer_request_poll();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
process_event_t codeprop_event_quit;
|