[Tinyos-2-commits] CVS: tinyos-2.x/apps/tests/TestTymo Makefile, NONE, 1.1 TestC.nc, NONE, 1.1 TestM.nc, NONE, 1.1 meyer-light.txt, NONE, 1.1 test.py, NONE, 1.1 topo.txt, NONE, 1.1 volumes-stm25p.xml, NONE, 1.1

Romain Thouvenin strabest at users.sourceforge.net
Mon Feb 18 13:52:46 PST 2008


Update of /cvsroot/tinyos/tinyos-2.x/apps/tests/TestTymo
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv28562/TestTymo

Added Files:
	Makefile TestC.nc TestM.nc meyer-light.txt test.py topo.txt 
	volumes-stm25p.xml 
Log Message:
Initial TestTymo commit

--- NEW FILE: Makefile ---
COMPONENT=TestC
PFLAGS += -I../../../tos/lib/net/tymo -I../../../tos/lib/net/tymo/dymo -I../../../tos/lib/net/tymo/mh
DOCDIR=~/tymo/web/html-doc/

include $(MAKERULES)
--- NEW FILE: TestC.nc ---

#define CC2420_DEF_RFPOWER 1
#define MAX_TABLE_SIZE 10
//#define DYMO_MONITORING

configuration TestC {

}

implementation {
  components TestM, DymoNetworkC;
  components MainC, LedsC, new TimerMilliC();

  TestM.Boot  -> MainC;
  TestM.Leds  -> LedsC;
  TestM.Timer -> TimerMilliC;
  TestM.SplitControl -> DymoNetworkC;
  TestM.Packet       -> DymoNetworkC;
  TestM.MHPacket     -> DymoNetworkC;
  TestM.Receive      -> DymoNetworkC.Receive[1];
  TestM.Intercept    -> DymoNetworkC.Intercept[1];
  TestM.MHSend       -> DymoNetworkC.MHSend[1];

#ifdef DYMO_MONITORING
  TestM.DymoMonitor -> DymoNetworkC;
#endif
}

--- NEW FILE: TestM.nc ---
#include "routing_table.h"

module TestM {
  
  uses {
    interface Boot;
    interface Leds;
    interface SplitControl;
    interface AMPacket as MHPacket;
    interface Packet;
    interface Receive;
    interface Intercept;
    interface AMSend as MHSend;
    interface Timer<TMilli>;
  }
#ifdef DYMO_MONITORING
  uses interface DymoMonitor;
#endif
}

implementation {

  message_t packet;

  enum {
    ORIGIN = 1,
    TARGET = 3,
  };

  void display(message_t * msg){
    uint8_t * payload = NULL;
    uint8_t size;
    int8_t i;
    dbg("messages", "message content:\n");
    for(i=0; i<size; i+=4, payload+=4){
      dbg("messages", "\t%hhu\t%hhu\t%hhu\t%hhu\n", *payload, *(payload+1), *(payload+2), *(payload+3));
    }
  }

  void setLeds(uint16_t val) {
    if (val & 0x01)
      call Leds.led0Toggle();
    if (val & 0x02)
      call Leds.led1Toggle();
    if (val & 0x04)
      call Leds.led2Toggle();
  }

  task void stop(){
    call SplitControl.stop();
  }

  event void Boot.booted(){
    call SplitControl.start();
  }

  event void SplitControl.startDone(error_t e){
    if(call MHPacket.address() == ORIGIN){
      call Timer.startPeriodic(2048);
    }
  }

  event void Timer.fired(){
    nx_uint16_t * payload = call Packet.getPayload(&packet, 2);
    error_t error;
    *payload = 1664;
    error = call MHSend.send(TARGET, &packet, sizeof(*payload));
    if(error == SUCCESS){
      dbg("messages", "Sending a beer...\n");
    } else {
      dbg("messages", "Unable to send the beer! - %hhu\n", error);
    }
  }

  event void MHSend.sendDone(message_t * msg, error_t e){
    if((e == SUCCESS) && (msg == &packet) && (call MHPacket.address() == ORIGIN)){
      dbg("messages", "Beer successfully sent.\n");
      setLeds(1);
    } else if (e == FAIL) {
      dbg("messages", "Sending the beer didn't succeed!\n");
      setLeds(2);
    } else {
      dbg("messages", "What the hell is going on!?");
    }
  }
  
  event message_t * Receive.receive(message_t * msg, void * payload, uint8_t len){
    if(call MHPacket.address() == TARGET){
      dbg("messages", "I have received a message from %u\n", call MHPacket.source(msg));
      dbg("messages", "It is a %u french beer, great! :o)\n", *(nx_uint16_t *)payload);
      setLeds(4);
    } else {
      dbg("messages", "What is this message?\n");
    }
    return msg;
  }

  event bool Intercept.forward(message_t * msg, void * payload, uint8_t len){
    setLeds(2);
    return TRUE;
  }

  event void SplitControl.stopDone(error_t e){}

#ifdef DYMO_MONITORING

  event void DymoMonitor.msgReceived(message_t * msg){
    dbg("messages", "Dymo msg received.\n");
  }

  event void DymoMonitor.msgSent(message_t * msg){
    dbg("messages", "Dymo msg sent.\n");
  }

  event void DymoMonitor.routeDiscovered(uint32_t delay, addr_t target){
    dbg("messages", "Route for %u discovered in %lu milliseconds.\n", target, delay);
  }

#endif

}

--- NEW FILE: meyer-light.txt ---
-39
-98
-98
-98
-99
-98
-94
-98
-98
-98
-98
-98
-99
-98
-98
-98
-98
-98
-98
-98
-97
-98
-97
-98
-98
-98
-98
-91
-98
-96
-96
-98
-98
-98
-98
-98
-99
-86
-97
-98
-98
-86
-90
-91
-87
-87
-98
-98
-98
-98
-98
-98
-78
-94
-90
-96
-98
-98
-98
-86
-98
-98
-98
-99
-98
-98
-98
-97
-99
-98
-98
-99
-98
-93
-98
-98
-82
-82
-81
-82
-82
-49
-98
-81
-82
-64
-81
-81
-98
-98
-98
-98
-98
-98
-98
-98
-98
-98
-98
-98

--- NEW FILE: test.py ---
from TOSSIM import *
import sys
import time

t = Tossim([])
r = t.radio()
f = open("topo.txt", "r")
n = 0

lines = f.readlines()
for line in lines:
  s = line.split()
  if (len(s) > 0):
#    print " ", s[0], " ", s[1], " ", s[2]
    r.add(int(s[0]), int(s[1]), float(s[2]))


t.addChannel("messages", sys.stdout)
#t.addChannel("fwe", sys.stdout)
#t.addChannel("mhe", sys.stdout)
#t.addChannel("de", sys.stdout)
t.addChannel("dt", sys.stdout)

noise = open("meyer-light.txt", "r")
lines = noise.readlines()
for line in lines:
  str = line.strip()
  if (str != ""):
    val = int(str)
    for i in range(1, 4):
      t.getNode(i).addNoiseTraceReading(val)

for i in range(1, 4):
#  print "Creating noise model for ",i
  t.getNode(i).createNoiseModel()

t.getNode(1).bootAtTime(100001);
t.getNode(2).bootAtTime(200022);
t.getNode(3).bootAtTime(300033);

t.runNextEvent();
time = t.time()
while (time + 700000000000 > t.time()):
  print t.time()
  t.runNextEvent()

sys.stderr.write("Finished!\n")

--- NEW FILE: topo.txt ---
1 2 -60.0

2 1 -60.0
2 3 -60.0

3 2 -60.0

--- NEW FILE: volumes-stm25p.xml ---
<volume_table>
  <volume name="DYMODATA" size="131072" />
</volume_table>



More information about the Tinyos-2-commits mailing list