[Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/tossim/sf/examples Makefile.Driver, NONE, 1.1 TestSerial.c, NONE, 1.1 TestSerial.py, NONE, 1.1 TestSerialSFClient.py, NONE, 1.1

Chad Metcalf hiro at users.sourceforge.net
Tue Oct 2 18:50:22 PDT 2007


Update of /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/sf/examples
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv27579/tos/lib/tossim/sf/examples

Added Files:
	Makefile.Driver TestSerial.c TestSerial.py 
	TestSerialSFClient.py 
Log Message:
The initial commit of the TOSSIM Live extensions. TOSSIM Live primary
function is to enable SF communications with a TOSSIM instance.
Examples are included to show how to use TOSSIM Live with the
TestSerial application.


--- NEW FILE: Makefile.Driver ---
#
# Copyright (c) 2007 Toilers Research Group - Colorado School of Mines
# 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.
# - Neither the name of Toilers Research Group - Colorado School of 
#   Mines  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 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 STANFORD
# UNIVERSITY OR ITS 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.
#*
# Author: Chad Metcalf
# Date: July 9, 2007
#

DRIVER_OBJS=build/micaz/c-sf.o build/micaz/sf.o build/micaz/tossim.o build/micaz/c-support.o build/micaz/sim.o build/micaz/pytossim.o build/micaz/throttle.o 

SFDIR=$(TOSCONTRIB)/csm/tos/lib/tossim

all:
	make micaz sim-sf
	g++ -g -c -o TestSerial.o TestSerial.c -I../../../tos/lib/tossim -I$(SFDIR) 
	g++ -o TestSerial $(DRIVER_OBJS)  TestSerial.o -lpython2.5 

clean:
	make clean
	rm -f TestSerial TestSerial.o *.pyc app.xml

--- NEW FILE: TestSerial.c ---
/*
 * Copyright (c) 2007 Toilers Research Group - Colorado School of Mines
 * 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.
 * - Neither the name of Toilers Research Group - Colorado School of 
 *   Mines  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 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 STANFORD
 * UNIVERSITY OR ITS 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.
 */
/**
 * Author: Chad Metcalf
 * Date: Oct 1, 2007
 *
 * A simple TOSSIM driver for the TestSerial application that utilizes 
 * TOSSIM Live extensions.
 *
 */

#include <stdio.h>
#include <tossim.h>
#include <SerialForwarder.h>
#include <Throttle.h>
#include <radio.h>
#include <math.h>
#include <unistd.h>

int main() {
 Tossim* t = new Tossim(NULL);
 t-> init();

 Throttle throttle(t, 10);
 SerialForwarder sf(9001);

 for (int i = 0; i < 1; i++) {
   Mote* m = t->getNode(i);
   m->bootAtTime(rand() % t->ticksPerSecond());
 }


 t->addChannel("Serial", stdout);
 t->addChannel("TestSerialC", stdout);
 t->addChannel("Atm128AlarmC", stdout);

 Radio* r = t->radio();
 for (int i = 0; i < 1; i++) {
    r->setNoise(i, -105.0, 1.0);
   for (int j = 0; j < 1; j++) {
      r->add(i, j, -96.0 - (double)abs(i - j));
      r->add(j, i, -96.0 - (double)abs(i - j));
   }
 }

sf.process();

 throttle.initialize();
 while(t->time() < 600 * t->ticksPerSecond()) {
   throttle.checkThrottle();
   sf.process();
   t->runNextEvent();
 }
}

--- NEW FILE: TestSerial.py ---
    #
# Copyright (c) 2007 Toilers Research Group - Colorado School of Mines
# 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.
# - Neither the name of Toilers Research Group - Colorado School of 
#   Mines  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 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 STANFORD
# UNIVERSITY OR ITS 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.
#*
# Author: Chad Metcalf
# Date: July 9, 2007
#
# A simple TOSSIM driver for the TestSerial application that utilizes 
# TOSSIM Live extensions.
#
import sys
import time

from TOSSIM import *
from TestSerialMsg import *

t = Tossim([])
m = t.mac()
r = t.radio()
sf = SerialForwarder(9001)
throttle = Throttle(t, 10)

t.addChannel("Serial", sys.stdout);
t.addChannel("TestSerialC", sys.stdout);

for i in range(0, 2):
  m = t.getNode(i);
  m.bootAtTime((31 + t.ticksPerSecond() / 10) * i + 1);

sf.process();
throttle.initialize();

for i in range(0, 60):
  throttle.checkThrottle();
  t.runNextEvent();
  sf.process();

msg = TestSerialMsg()
msg.set_counter(7);

serialpkt = t.newSerialPacket();
serialpkt.setData(msg.data)
serialpkt.setType(msg.get_amType())
serialpkt.setDestination(0)
serialpkt.deliver(0, t.time() + 3)

pkt = t.newPacket();
pkt.setData(msg.data)
pkt.setType(msg.get_amType())
pkt.setDestination(0)
pkt.deliver(0, t.time() + 10)

for i in range(0, 20):
  throttle.checkThrottle();
  t.runNextEvent();
  sf.process();

throttle.printStatistics()

--- NEW FILE: TestSerialSFClient.py ---
#!/usr/bin/env python
#
# Copyright (c) 2007 Toilers Research Group - Colorado School of Mines
# 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.
# - Neither the name of Toilers Research Group - Colorado School of 
#   Mines  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 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 STANFORD
# UNIVERSITY OR ITS 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.
#*
# Author: Chad Metcalf
# Date: July 9, 2007
#
# A simple Python script that listens on a SF for TestSerial messages.

from TestSerialMsg import *
from tinyos.message import MoteIF

class MyClass:
    def __init__(self):
        # Create a MoteIF
        self.mif = MoteIF.MoteIF()
        # Attach a source to it
        self.source = self.mif.addSource("sf at localhost:9001")

        # SomeMessageClass.py would be generated by MIG
        self.mif.addListener(self, TestSerialMsg)

    # Called by the MoteIF's receive thread when a new message
    # is received
    def receive(self, src, msg):
        print "Received message: "+ str(msg)

if __name__ == "__main__":
    m = MyClass()



More information about the Tinyos-2-commits mailing list