[Tinyos-2-commits] CVS: tinyos-2.x/apps/UDPEcho/NodeConnectivity NodeConnectivity.nc, NONE, 1.1 TestbedConnectivityM.nc, NONE, 1.1 createNodeConnectivityM.pl, NONE, 1.1 exampleMap.txt, NONE, 1.1 testBed.nss, NONE, 1.1 testBedMap.txt, NONE, 1.1

sdhsdh sdhsdh at users.sourceforge.net
Mon Jan 19 16:33:24 PST 2009


Update of /cvsroot/tinyos/tinyos-2.x/apps/UDPEcho/NodeConnectivity
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv7358/UDPEcho/NodeConnectivity

Added Files:
	NodeConnectivity.nc TestbedConnectivityM.nc 
	createNodeConnectivityM.pl exampleMap.txt testBed.nss 
	testBedMap.txt 
Log Message:
 - commit blip stack apps



--- NEW FILE: NodeConnectivity.nc ---
/*
 * "Copyright (c) 2008 The Regents of the University  of California.
 * All rights reserved."
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose, without fee, and without written agreement is
 * hereby granted, provided that the above copyright notice, the following
 * two paragraphs and the author appear in all copies of this software.
 *
 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
 * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
 *
 */
// For conversion of topology from .nss to motelab
// See NodeConnectivityM.nc 

interface NodeConnectivity {
  command int8_t mapping(uint16_t moteid);
  command bool connected(uint16_t srcnode, uint16_t dstnode);
}

--- NEW FILE: TestbedConnectivityM.nc ---
/*
 * "Copyright (c) 2008 The Regents of the University  of California.
 * All rights reserved."
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose, without fee, and without written agreement is
 * hereby granted, provided that the above copyright notice, the following
 * two paragraphs and the author appear in all copies of this software.
 *
 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
 * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
 *
 */
// Filename: NodeConnectivityM.nc
// Generated on Wed Jun 11 19:54:54 UTC 2008

// Created by createMotelabTopology.pl

module TestbedConnectivityM {
  provides {
    interface NodeConnectivity;
  }
} implementation {
  uint8_t connectivity[8][8] =
  {
    { 1, 1, 0, 0, 0, 0, 0, 0 },
    { 1, 1, 1, 0, 0, 0, 0, 0 },
    { 0, 1, 1, 1, 0, 0, 0, 0 },
    { 0, 0, 1, 1, 1, 0, 0, 0 },
    { 0, 0, 0, 1, 1, 1, 0, 0 },
    { 0, 0, 0, 0, 1, 1, 1, 0 },
    { 0, 0, 0, 0, 0, 1, 1, 1 },
    { 0, 0, 0, 0, 0, 0, 1, 1 }
  };
  uint16_t mapping[8] = { 100, 101, 102, 37, 35, 33, 32, 106 };
  
  command int8_t NodeConnectivity.mapping(uint16_t moteid) {
    uint8_t i;
    for (i = 0; i < 8; i++) {
      if (mapping[i] == moteid) {
        return i;
      }
    }
    return -1;
  }

  command bool NodeConnectivity.connected(uint16_t srcnode, uint16_t dstnode) {
    int8_t src = call NodeConnectivity.mapping(srcnode);
    int8_t dst = call NodeConnectivity.mapping(dstnode);

    if ((src == -1) ||
        (dst == -1)) {
      return FALSE;
    }

    if (connectivity[src][dst] == 1) {
      return TRUE;
    } else {
      return FALSE;
    }
  }
}

--- NEW FILE: createNodeConnectivityM.pl ---
#!/usr/bin/perl

# FileName:    createMotelabTopology.pl 
# Date:        December 31, 2004
#
# Description: Converts a TOSSIM .nss (topology) file into Motelab format
# Usage:  ./createMotelabTopology.pl  .nssfile     

# Input:  A TOSSIM .nss topology file
# Output: A nesc file containing a 2D array that represents 
#         the latency for each node and a func that returns true or false
#         as to whether that node can communicate with other nodes


use strict;

######################
#                    #
#  Parse Parameters  #
#                    #
######################

if ( 2 > @ARGV ) {
    die "Usage: ./createMotelabTopology <mapfile(see exampleMap.txt as a sample)>  <.nss file> ";
}

#######################
#                     #
#  Open file handles  #
#                     #
#######################

open(INPUT_MAP,  "$ARGV[0]")
    or die "Unable to open input file $ARGV[0] ($!)";

open(INPUT_NSS,  "$ARGV[1]")
    or die "Unable to open input file $ARGV[1] ($!)";

#########################
#                       #
#  Parse and store file #
#  outputs              #
#                       #
#########################

my @mappingArray;
while (my @input = split(/\s+/, <INPUT_MAP>)) {
  $mappingArray[$input[0]] = $input[1];
}

my %probHash;
my $maxI = 0;
my $maxJ = 0;

while (my @input = split(/:/, <INPUT_NSS>)) {

  # 09 Jan 2005 : GWA : Yikes, not sure about ordering here.  Also what the
  #               .nss file includes is the bit error probability,
  #               essentially the inverse of what we want.

  $probHash{"$input[0]x$input[1]"} = (1 - $input[2]);
  
  if ($input[0] > $maxI) {
    $maxI = $input[0];
  }
  if ($input[1] > $maxJ) {
    $maxJ = $input[1];
  }
}

#############################
#                           #
#  Write out the nesC code  #
#                           #
#############################

my $dateString = `date`;
print <<TOP;
// Filename: NodeConnectivityM.nc
// Generated on $dateString
// Created by createMotelabTopology.pl

module NodeConnectivityM {
  provides {
    interface NodeConnectivity;
  }
} implementation {
TOP

my $arrayWidth = $maxI + 1;
my $arrayHeight = $maxJ + 1;
my $connectivityString = <<START;
  uint8_t connectivity[$arrayWidth][$arrayHeight] =
  {
START
$connectivityString .= "    ";
for (my $i = 0; $i <= $maxI; $i++) {
  $connectivityString .= "{ ";
  for (my $j = 0; $j <= $maxJ; $j++) {
    if ($i == $j) {
      $connectivityString .= "1";
    } elsif (!defined($probHash{"$i" . "x" . "$j"})) {
      $connectivityString .= "0";
    } else {
      $connectivityString .= $probHash{"$i" . "x" . "$j"};
    }
    if ($j != $maxJ) {
      $connectivityString .= ", ";
    }
  }
  $connectivityString .= " }";
  if ($i != $maxI) {
    $connectivityString .= ",";
  }
  $connectivityString .= "\n";
  if ($i != $maxI) {
    $connectivityString .= "    ";
  }
}
$connectivityString .= <<END;
  };
END
print "$connectivityString";

my $mappingString = "{ ";
my $mappingSize = @mappingArray;
for (my $i = 0; $i < @mappingArray; $i++) {
  $mappingString .= $mappingArray[$i];
  if ($i != (@mappingArray - 1)) {
    $mappingString .= ", ";
  }
}
$mappingString .= " };";

print <<MAPPING;
  uint16_t mapping[$mappingSize] = $mappingString
MAPPING

print <<REALEND;
  
  command int8_t NodeConnectivity.mapping(uint16_t moteid) {
    uint8_t i;
    for (i = 0; i < $mappingSize; i++) {
      if (mapping[i] == moteid) {
        return i;
      }
    }
    return -1;
  }

  command bool NodeConnectivity.connected(uint16_t srcnode, uint16_t dstnode) {
    int8_t src = call NodeConnectivity.mapping(srcnode);
    int8_t dst = call NodeConnectivity.mapping(dstnode);

    if ((src == -1) ||
        (dst == -1)) {
      return FALSE;
    }

    if (connectivity[src][dst] == 1) {
      return TRUE;
    } else {
      return FALSE;
    }
  }
}
REALEND

--- NEW FILE: exampleMap.txt ---
0 12
1 30
2 24
3 7
4 18
5 4
6 28
7 2
8 16
9 1
10 22
11 13
12 23
13 25
14 26
15 5

--- NEW FILE: testBed.nss ---
0:1:0.0
0:2:1.0
0:3:1.0
0:4:1.0
0:5:1.0
0:6:1.0
0:7:1.0

1:0:0.0
1:2:0.0
1:3:1.0
1:4:1.0
1:5:1.0
1:6:1.0
1:7:1.0

2:0:1.0
2:1:0.0
2:3:0.0
2:4:1.0
2:5:1.0
2:6:1.0
2:7:1.0

3:0:1.0
3:1:1.0
3:2:0.0
3:4:0.0
3:5:1.0
3:6:1.0
3:7:1.0

4:0:1.0
4:1:1.0
4:2:1.0
4:3:0.0
4:5:0.0
4:6:1.0
4:7:1.0

5:0:1.0
5:1:1.0
5:2:1.0
5:3:1.0
5:4:0.0
5:6:0.0
5:7:1.0

6:0:1.0
6:1:1.0
6:2:1.0
6:3:1.0
6:4:1.0
6:5:0.0
6:7:0.0

7:0:1.0
7:1:1.0
7:2:1.0
7:3:1.0
7:4:1.0
7:6:0.0


--- NEW FILE: testBedMap.txt ---
0 100
1 101
2 102
3 103
4 104
5 105
6 106
7 107



More information about the Tinyos-2-commits mailing list