[Tinyos-2-commits] CVS: tinyos-2.x/apps/6lowpancli CliAppC.nc, NONE, 1.1 CliC.nc, NONE, 1.1 Makefile, NONE, 1.1 README, NONE, 1.1

Matus Harvan mharvan at users.sourceforge.net
Wed Dec 5 14:58:43 PST 2007


Update of /cvsroot/tinyos/tinyos-2.x/apps/6lowpancli
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv11742/apps/6lowpancli

Added Files:
	CliAppC.nc CliC.nc Makefile README 
Log Message:
6lowpan import


--- NEW FILE: CliAppC.nc ---
/*
 * Copyright (c) 2007 Matus Harvan
 * All rights reserved
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * 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.
 *     * The name of the author may not be used to endorse or promote
 *       products derived from this software without specific prior
 *       written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
 * OWNER 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.
 */
#include "printf.h"

#if defined(ENABLE_MICAZ_TEMP_SENSOR) || defined(ENABLE_TELOSB_TEMP_SENSOR)
#define ENABLE_TEMP_SENSOR
#endif /* ENABLE_MICAZ_TEMP_SENSOR || ENABLE_TELOSB_TEMP_SENSOR */

#if defined(ENABLE_MICAZ_LIGHT_SENSOR) || defined(ENABLE_TELOSB_LIGHT_SENSOR)
#define ENABLE_LIGHT_SENSOR
#endif /* ENABLE_MICAZ_LIGHT_SENSOR || ENABLE_TELOSB_LIGHT_SENSOR */

enum {
    AM_IP_MSG = 0x41,
};

configuration CliAppC {}
implementation {
    components CliC as App, LedsC, MainC;
    components IPC;
    
    App.Boot -> MainC.Boot;
    App.Leds -> LedsC;
    App.IPControl -> IPC.IPControl;
    App.IP -> IPC.IP;
    App.UDPClient -> IPC.UDPClient[unique("UDPClient")];

#ifdef ENABLE_SOUNDER
    components SounderC;
    App.Sounder -> SounderC;
#endif /* ENABLE_SOUNDER */

#ifdef ENABLE_MICAZ_TEMP_SENSOR
    components new TempC(); // telosb temp/humidity sensor
    App.TempSensorC -> TempC;
#endif /* ENABLE_MICAZ_TEMP_SENSOR */

#ifdef ENABLE_TELOSB_TEMP_SENSOR
    components new SensirionSht11C(); // telosb temp/humidity sensor
    App.TempSensorC -> SensirionSht11C.Temperature;
#endif /* ENABLE_TELOSB_TEMP_SENSOR */

#ifdef ENABLE_MICAZ_LIGHT_SENSOR
    components new PhotoC();// telosb visible light sensor
    App.LightSensorC -> PhotoC;
#endif /* ENABLE_MICAZ_TEMP_SENSOR */

#ifdef ENABLE_TELOSB_LIGHT_SENSOR
    // total solar radiation sensor
    //new HamamatsuS10871TsrC() as Sensor, // telosb (IR) light sensor
    // photosynthetically-active radiation sensor
    components new HamamatsuS1087ParC();// telosb visible light sensor
    App.LightSensorC -> HamamatsuS1087ParC;
#endif /* ENABLE_TELOSB_TEMP_SENSOR */
}




--- NEW FILE: CliC.nc ---
/*
 * Copyright (c) 2007 Matus Harvan
 * All rights reserved
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * 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.
 *     * The name of the author may not be used to endorse or promote
 *       products derived from this software without specific prior
 *       written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
 * OWNER 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.
 */

#include "Timer.h"

#define min(a,b) ( (a>b) ? b : a )
#define max(a,b) ( (a>b) ? a : b )

module CliC {
  uses {
    interface Leds;
    interface Boot;
    interface IP;
    interface UDPClient;
    interface SplitControl as IPControl;
#ifdef ENABLE_SOUNDER
    interface Mts300Sounder as Sounder;
#endif /* ENABLE_SOUNDER */
#ifdef ENABLE_TEMP_SENSOR
    interface Read<uint16_t> as TempSensorC;
#endif /* ENABLE_TEMP_SENSOR */
#ifdef ENABLE_LIGHT_SENSOR
    interface Read<uint16_t> as LightSensorC;
#endif /* ENABLE_LIGHT_SENSOR */
  }
}
implementation {
#ifndef MINIMIZE_MEMORY
    char *help_buf = "6lowpan cli supported commands:\n"
                     "\tset led {0,1,2} {on,off} -- toggle leds\n"
#ifdef ENABLE_SOUNDER
                     "\tsounder time_in_ms\n"
#endif /* ENABLE_SOUNDER */
#ifdef ENABLE_TEMP_SENSOR
                     "\tget temp\n"
#endif /* ENABLE_TEMP_SENSOR */
#ifdef ENABLE_LIGHT_SENSOR
                     "\tget light\n"
#endif /* ENABLE_LIGHT_SENSOR */
                     "\tsend small udp\n"
                     "\tsend large udp\n"
                     "\thelp\n";
    char *small_udp_buf = "\n";
    char *large_udp_buf = "\n";
    /*
    char *small_udp_buf = "----- SMALL UDP DATA BUFFER -----\n";
    char *large_udp_buf =
	    "This is a large testing string. It should undergo " \
	    "6lowpan fragmentation\n" \
            "0............................................................\n" \
            "1............................................................\n" \
            "2............................................................\n" \
            "3............................................................\n" \
            "4............................................................\n" \
            "5............................................................\n" \
            "6............................................................\n" \
            "7............................................................\n" \
            "8............................................................\n" \
            "9............................................................\n" \
            "A............................................................\n" \
            "B............................................................\n" \
            "C............................................................\n" \
            "D............................................................\n" \
            "E............................................................\n" \
            "10...........................................................\n" \
            "11...........................................................\n" \
            "12...........................................................\n" \
            "13(shorter)\n" \
	    "---- END OF THE LARGE UDP DATA ----\n";
    */
#if defined(ENABLE_TEMP_SENSOR) || defined(ENABLE_LIGHT_SENSOR)
    char sensor_buf[15];
    bool sensor_buf_busy = FALSE;
    ip6_addr_t sensor_addr;
    uint16_t sensor_port;
#endif /* ENABLE_TEMP_SENSOR | ENABLE_LIGHT_SENSOR */
#endif /* MINIMIZE_MEMORY */

    event void Boot.booted() {
      /* set an IP address */
      ip6_addr_t addr = {{0x20, 0x01,
			 0x06, 0x38,
			 0x07, 0x09,
			 0x12, 0x34,
			 0x00, 0x00,
			 0x00, 0x00,
			 0x00, 0x00,
			 0x00, 0x00
      }};
      //call IP.setAddress(&addr);
        call IP.setAddressAutoconf(&addr);

	call IPControl.start();
    }
    
    event void IPControl.startDone(error_t err) {

	call UDPClient.listen(1234);
    }
    event void IPControl.stopDone(error_t err) {}

    event void UDPClient.receive(const ip6_addr_t *addr, const uint16_t port,
				 uint8_t *buf, uint16_t len )
    {
#ifndef MINIMIZE_MEMORY
	if ( strncmp(buf, "set ", min(len, 4)) == 0 && len>0) {
	    buf += 4;
	    len -= 4;
	    if ( strncmp(buf, "led ", min(len, 4)) == 0 && len>0) {
		buf += 4;
		len -= 4;

		if ( strncmp(buf, "0 ", min(len, 2)) == 0 && len>0) {
		    buf += 2;
		    len -= 2;
		    if ( strncmp(buf, "on", min(len, 2)) == 0 && len>0) {
			call Leds.led0On();
		    } else if (strncmp(buf, "off", min(len, 3)) == 0 && len>0){
			call Leds.led0Off();
		    }
		} else if ( strncmp(buf, "1 ", min(len, 2)) == 0 && len>0) {
		    buf += 2;
		    len -= 2;
		    if ( strncmp(buf, "on", min(len, 2)) == 0 && len>0) {
			call Leds.led1On();
		    } else if (strncmp(buf, "off", min(len, 3)) == 0 && len>0){
			call Leds.led1Off();
		    }
		} else if ( strncmp(buf, "2 ", min(len, 2)) == 0 && len>0) {
		    buf += 2;
		    len -= 2;
		    if ( strncmp(buf, "on", min(len, 2)) == 0 && len>0) {
			call Leds.led2On();
		    } else if (strncmp(buf, "off", min(len, 3)) == 0 && len>0){
			call Leds.led2Off();
		    }
		} 
	    }
#ifdef ENABLE_SOUNDER
	} else if ( strncmp(buf, "sounder ", min(len, 8)) == 0
		    && len>0) {
	    buf += 8;
	    len -= 8;
	    call Sounder.beep(atoi(buf));
#endif /* ENABLE_SOUNDER */

#ifdef ENABLE_TEMP_SENSOR
	} else if ( strncmp(buf, "get temp", min(len, 8)) == 0
		    && len>0) {
	    memcpy(&sensor_addr, addr, sizeof(*addr));
	    sensor_port = port;
	    //call UDPClient.sendTo(addr, port, "reading temp...\n", 16);
	    call TempSensorC.read();
#endif /* ENABLE_TEMP_SENSOR */

#ifdef ENABLE_LIGHT_SENSOR
	} else if ( strncmp(buf, "get light", min(len, 8)) == 0
		    && len>0) {
	    memcpy(&sensor_addr, addr, sizeof(*addr));
	    sensor_port = port;
	    //call UDPClient.sendTo(addr, port, "reading light...\n", 17);
	    call LightSensorC.read();
#endif /* ENABLE_LIGHT_SENSOR */

	} else if (strncmp(buf, "send large udp", min(len, 14)) == 0
		   && len>0) {
	    call UDPClient.sendTo(addr, port,
				  large_udp_buf, strlen(large_udp_buf));
	} else if (strncmp(buf, "send small udp", min(len, 14)) == 0
		   && len>0) {
	    call UDPClient.sendTo(addr, port,
				  small_udp_buf, strlen(small_udp_buf));
	} else if (strncmp(buf, "help", min(len, 14)) == 0
		   && len>0) {
	    call UDPClient.sendTo(addr, port,
				  help_buf, strlen(help_buf));
	} else {
	    call UDPClient.sendTo(addr, port,
				  help_buf, strlen(help_buf));
	}
#endif /* MINIMIZE_MEMORY */
    }
    
    event void UDPClient.sendDone(error_t result, void* buf)
    {
#if defined(ENABLE_TEMP_SENSOR) || defined(ENABLE_LIGHT_SENSOR)
	if (buf == sensor_buf) {
	    sensor_buf_busy = FALSE;
	}
#endif /* ENABLE_TEMP_SENSOR | ENABLE_LIGHT_SENSOR */
    }

#ifdef ENABLE_TEMP_SENSOR
  event void TempSensorC.readDone(error_t result, uint16_t data) {
      if (sensor_buf_busy == FALSE) {
	  sensor_buf_busy = TRUE;
	  if (result == SUCCESS) {
	      snprintf(sensor_buf, sizeof(sensor_buf), "temp: %d\n", data);
	  } else {
	      snprintf(sensor_buf, sizeof(sensor_buf), "temp: -\n");
	  }
	  call UDPClient.sendTo(&sensor_addr, sensor_port,
				sensor_buf, strlen(sensor_buf));
      } else {
	  call UDPClient.sendTo(&sensor_addr, sensor_port,
				"busy\n", 5);
      }
  }
#endif /* ENABLE_TEMP_SENSOR */

#ifdef ENABLE_LIGHT_SENSOR
  event void LightSensorC.readDone(error_t result, uint16_t data) {
      if (sensor_buf_busy == FALSE) {
	  sensor_buf_busy = TRUE;
	  if (result == SUCCESS) {
	      snprintf(sensor_buf, sizeof(sensor_buf), "light: %d\n", data);
	  } else {
	      snprintf(sensor_buf, sizeof(sensor_buf), "light: -\n");
	  }
	  call UDPClient.sendTo(&sensor_addr, sensor_port,
				sensor_buf, strlen(sensor_buf));
      } else {
	  call UDPClient.sendTo(&sensor_addr, sensor_port,
				"busy\n", 5);
      }
  }
#endif /* ENABLE_LIGHT_SENSOR */
}

--- NEW FILE: Makefile ---
COMPONENT=CliAppC

CFLAGS += -I$(TOSDIR)/lib/printf -I$(TOSDIR)/lib/net/6lowpan -D'TOSH_DATA_LENGTH=102'

# TelosB
# CFLAGS + = "-D'ENABLE_TELOSB_LIGHT_SENSOR=1' -D'ENABLE_TELOSB_TEMP_SENSOR=1'"

# MicaZ with the mts300 sensorboard
# CFLAGS += "-D'ENABLE_MICAZ_LIGHT_SENSOR=1' -D'ENABLE_MICAZ_TEMP_SENSOR=1' -D'ENABLE_SOUNDER=1'"


include $(MAKERULES)

--- NEW FILE: README ---
6lowpan cli is a sample application using the 6lowpan stack. It
implements a cli listening on UDP port 1234 for commands and replying
with answers.

Besides that, the mote answers to pings.

The IPv6 addresses
 * a global address with prefix 2001:0638:0709:1234::/64
 * a link-local address
are assigned using an interface identifier computed from the Active
Message address of the mote. This is almost like the stateless
autoconfiguration, but Duplicate Address Detection or Router
Solicitations are not implemented.


Note that you also need a BaseStation application and the serial_tun
daemon running. See tos/lib/net/6lowpan/REAME for more details.

			       BUILDING
Debugging output with printf over USB can be enabled with
	CFLAGS="-D'ENABLE_PRINTF_DEBUG=1'

To minimize memory usage, i.e. disable everything (at the moment only
the UDP cli) to determine minimum RAM/ROM requirements, use
	CFLAGS="-D'MINIMIZE_MEMORY=1'


			       TESTING
Assuming active message address (mote id) 20 (0x14):

Small unfragmented ping
	sudo ping6 -s 50 2001:638:709:1234::fffe:14

Large fragmented ping
	sudo ping6 -s 1230 -i 3 2001:638:709:1234::fffe:14

Link-local all-nodes ping
	sudo ping6 -s 20 ff02::01

UDP cli
	nc6 -u  2001:638:709:1234::fffe:14 1234	




More information about the Tinyos-2-commits mailing list