[Tinyos-2-commits] CVS: tinyos-2.x/apps/tests/TestFtsp/Ftsp FtspDataAnalyzer.m, NONE, 1.1 FtspDataLogger.java, NONE, 1.1 FtspDataLogger.py, NONE, 1.1 Makefile, NONE, 1.1 README.MATLAB.txt, NONE, 1.1 README.txt, NONE, 1.1 TestFtsp.h, NONE, 1.1 TestFtspAppC.nc, NONE, 1.1 TestFtspC.nc, NONE, 1.1

kusy kusy at users.sourceforge.net
Wed Jul 15 23:59:40 PDT 2009


Update of /cvsroot/tinyos/tinyos-2.x/apps/tests/TestFtsp/Ftsp
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv18289/Ftsp

Added Files:
	FtspDataAnalyzer.m FtspDataLogger.java FtspDataLogger.py 
	Makefile README.MATLAB.txt README.txt TestFtsp.h 
	TestFtspAppC.nc TestFtspC.nc 
Log Message:
Reorganizing directory: enabling LPL, 32khz clock for certain platforms. Patches thanks to Thomas Schmidt

--- NEW FILE: FtspDataAnalyzer.m ---
%load file written out by FtspDataLogger.java class

%arg0 - filename, e.g. '1205543689171.report'

function FTSPDataAnalyzer(file, varargin)

[c1 c2 c3 c4 c5]= textread(file, '%u %u %u %u %u', 'commentstyle', 'shell');

data = [c2 c3 c4 c5]; %skipping the first column (java time)

data1 = sortrows(sortrows(data,1),2);

newdata = [];



row=1;

newrow=1;

unsynced=0;

while (row<=size(data1,1))



    seqnum=data1(row,2);



    data2=[];

    row2=1;

    tmprow1=row;

    while (row <= size(data1,1) && data1(row,2)==seqnum)

        if (data1(row,4)==0)

            data2(row2,1)=data1(row,3);

            row2= row2+ 1;

        else

            unsynced=unsynced+1;

        end

        row = row + 1;

    end

    

    if (row2>1)

        row2size=row2-1;

        rcvdsize=row-tmprow1;

        newdata(newrow,1) = seqnum;

        newdata(newrow,2) = mad(data2(1:row2size,1));

        newdata(newrow,3) = mean(data2(1:row2size,1));

        newdata(newrow,4) = row2size/rcvdsize;

        newrow = newrow + 1;

    end

end



if (length(newdata)==0)

    disp('no data found (at least one data point from a synchronized mote is required)!');

else

    newsize=newrow-1;

    subplot(3,1,1);

    plot(newdata(1:newsize,1),newdata(1:newsize,2));

    title(sprintf('TimeSync Errors'));

    subplot(3,1,2);

    plot(newdata(1:newsize,1),newdata(1:newsize,3));

    title(sprintf('Avg Glob Time'));

    subplot(3,1,3);

    plot(newdata(1:newsize,1),newdata(1:newsize,4),'b-');

    title(sprintf('%% Synced Motes'));



    disp(sprintf('total unsycned num %d (all %d)',unsynced,newsize));

    disp(sprintf('avg %0.3f',mean(newdata(1:newsize,2))));

    disp(sprintf('max %d',max(newdata(1:newsize,2))));

    savedata = newdata(1:newsize,:);

    save data.out savedata -ASCII;

end

    
--- NEW FILE: FtspDataLogger.java ---
/*                  tab:4
 * "Copyright (c) 2000-2003 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."
 *
 * Copyright (c) 2002-2007 Intel Corporation
 * All rights reserved.
 *
 * This file is distributed under the terms in the attached INTEL-LICENSE
 * file. If you do not find these files, copies can be found by writing to
 * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
 * 94704.  Attention:  Intel License Inquiry.
 */


/**
 * @author Brano Kusy
 */

import java.io.FileOutputStream;
import java.io.PrintStream;
import net.tinyos.message.*;
import net.tinyos.util.*;

public class FtspDataLogger implements MessageListener {
        public class RunWhenShuttingDown extends Thread {
                public void run()
                {
                        System.out.println("Control-C caught. Shutting down...");
                        if (outReport!=null)
                        outReport.close();
                }
        }

  MoteIF mote;    // For talking to the antitheft root node

        void connect()
        {
                try {
                        mote = new MoteIF(PrintStreamMessenger.err);
                        mote.registerListener(new TestFtspMsg(), this);
                        System.out.println("Connection ok!");
                }
                catch(Exception e) {
                        e.printStackTrace();
                        System.exit(2);
                }
        }
        PrintStream outReport = null;

        public FtspDataLogger() {
                connect();
                Runtime.getRuntime().addShutdownHook(new RunWhenShuttingDown());
                String name=""+System.currentTimeMillis();
                try
                {
                        outReport = new PrintStream(new FileOutputStream(name+".report"));
                        outReport.println("#[JAVA_TIME] [NODE_ID] [SEQ_NUM] [GLOB_TIME] [IS_TIME_VALID]");
                }
                catch (Exception e)
                {
                        System.out.println("FtspDataLogger.FtspDataLogger(): "+e.toString());
                }
        }

        public void writeReprot(TestFtspMsg tspr)
        {
                String foo = (System.currentTimeMillis()
                		+" "+tspr.get_src_addr()+" "+tspr.get_counter()
                        +" "+tspr.get_global_rx_timestamp()+" "+tspr.get_is_synced());
                outReport.println(foo);
                System.out.println(foo);
                outReport.flush();
        }

        public void writeFullReprot(TestFtspMsg tspr)
        {
                String foo = (System.currentTimeMillis()
                		+" "+tspr.get_src_addr()
                        +" "+tspr.get_counter()
                        +" "+tspr.get_local_rx_timestamp()
                        +" "+tspr.get_global_rx_timestamp()
                        +" "+tspr.get_skew_times_1000000()
                        +" "+tspr.get_is_synced()
                        +" "+tspr.get_ftsp_root_addr()
                        +" "+tspr.get_ftsp_seq()
                        +" "+tspr.get_ftsp_table_entries());
                outReport.println(foo);
                System.out.println(foo);
                outReport.flush();
        }

        public void messageReceived(int dest_addr, Message msg)
        {
                if (msg instanceof TestFtspMsg)
                        //writeFullReprot((TestFtspMsg)msg);
                        writeReprot((TestFtspMsg)msg);
        }

        /* Just start the app... */
        public static void main(String[] args)
        {
                new FtspDataLogger();
        }
}
--- NEW FILE: FtspDataLogger.py ---
#!/usr/bin/env python

import sys, time
import tos

AM_TEST_FTSP_MSG = 137

class FtspMsg(tos.Packet):
    def __init__(self, packet = None):
        tos.Packet.__init__(self,
                            [('src_addr',            'int', 2),
                             ('counter',             'int', 2),
                             ('local_rx_timestamp',  'int', 4),
                             ('global_rx_timestamp', 'int', 4),
                             ('skew_times_1000000',  'int', 4),
                             ('is_synced',           'int', 1),
                             ('ftsp_root_addr',      'int', 2),
                             ('ftsp_seq',            'int', 1),
                             ('ftsp_table_entries',  'int', 2)],
                            packet)

if '-h' in sys.argv:
    print "Usage:", sys.argv[0], "serial@/dev/ttyUSB0:57600"
    sys.exit()

am = tos.AM()

while True:
    p = am.read()
    if p and p.type == AM_TEST_FTSP_MSG:
        msg = FtspMsg(p.data)
        print int(time.time()), msg.src_addr, msg.counter, msg.global_rx_timestamp, msg.is_synced
        #print msg

--- NEW FILE: Makefile ---
BUILD_EXTRA_DEPS = FtspDataLogger.class
CLEAN_EXTRA = *.class TestFtspMsg.java

FtspDataLogger.class: TestFtspMsg.java
	javac *.java

TestFtspMsg.java: TestFtsp.h
	mig java -target=$(PLATFORM) $(CFLAGS) -java-classname=TestFtspMsg TestFtsp.h test_ftsp_msg -o $@

COMPONENT=TestFtspAppC

PFLAGS += -DTIMESYNC_RATE=3
#PFLAGS += -DTIMESYNC_DEBUG

PFLAGS += -I$(TOSDIR)/lib/ftsp -I$(TOSDIR)/../apps/RadioCountToLeds

include $(MAKERULES)

--- NEW FILE: README.MATLAB.txt ---
FtspDataAnalyzer.m



-------------------------------------------------------------------------------

Author/Contact:

---------------

 Brano Kusy: branislav.kusy at gmail.com



-------------------------------------------------------------------------------

DESCRIPTION:

------------



FtspDataAnalyzer.m works with data logs collected by FtspDataLogger.java and

calculates the maximum and average timesync error over time.



-------------------------------------------------------------------------------

STEP BY STEP GUIDE TO RUN OUR TEST SCENARIO:

--------------------------------------------

1. program and start motes as described in ./README.txt

2. start SerialForwarder and FtspDataLogger.java as described in ./README.txt

3. 'current_time.report' file (where current_time is a number) is created in ./

   this file is updated with data in the real time

4. let the experiment run for some time

5. start matlab and enter (assuming your current_time was 1206126224593)

    FTSPDataAnalyzer('1206126224593.report')

    this will plot the mean absolute timesync error, global time, and number of

    synced motes; this can be done while experiment is running

6. Matlab also creates data.out file which contains data in the following format

    #seqNum mean_abs_error global_time num_synced_motes

    mean_abs_error is calculated as mean absolute deviation from the mean (mad)



Simulating multi-hop:

1. define TIMESYNC_DEBUG in the Makefile

2. recompile and upload TestFTSP app to n motes with special NODE_IDs:

     using 'make micaz reinstall.0xAB', nodes 0xAB and 0xCD can communicate

     iff 2D grid coordinates (A,B) and (C,D) are neighbors in a 2D grid

 

-------------------------------------------------------------------------------

EVALUATION:

--------------------------------------------

 - deployment setup: 11 nodes in a 5x3 grid using simulated multi-hop (4 points

   were vacant as we only used 11 nodes). the max number of hops was 5.

 - parameters: sync period 10sec, polling period 3 sec

 - experiment length: 100 minutes

 - results (1 jiffy is ~30.5 us)

    1.53 jiffy avg error (~50us)

    3.5 jiffy max error (~100us)
--- NEW FILE: README.txt ---
TestFtsp

-------------------------------------------------------------------------------
Author/Contact:
---------------
 Brano Kusy: branislav.kusy at gmail.com
 Janos Sallai: janos.sallai at vanderbilt.edu
 Miklos Maroti: mmaroti at gmail.com

-------------------------------------------------------------------------------
DESCRIPTION:
------------
 The TestFtsp application tests the Flooding Time Synchronization Protocol
 (FTSP) implementation. A network of motes programmed with TestFtsp run the
 FTSP protocol to time synchronize, and sends to the base station the global
 reception timestamps of messages broadcast by a dedicated beacon mote
 programmed with RadioCountToLeds. Ideally, the global reception timestamps of
 the same RadioCountToLeds message should agree for all TestFtsp motes (with a
 small synchronization error).

-------------------------------------------------------------------------------
SUPPORTED PLATFORMS:
--------------------------------------------
 The supported platforms are micaz, telosb and iris.

-------------------------------------------------------------------------------
STEP BY STEP GUIDE TO RUN OUR TEST SCENARIO:
--------------------------------------------
 - program one mote with apps/RadioCountToLeds
 - program multiple motes with TestFtsp
 - program a mote with apps/BaseStation, leave it on the programming board
 - turn on all the motes
 - start the FtspDataLogger java application (type "java FtspDataLogger")

-------------------------------------------------------------------------------
REPORTED DATA:
--------------
 The most important reported data is the global time of arrival of the beacons.
 The beacon msg arrives to all clients at the same time instant, thus reported
 global times should be the same for all clients for the same sequence number.

 Each message contains:
 - the time of message reception by the java app [JAVA_TIME]
 - the node ID of the mote that is sending this report [NODE_ID]
 - the  sequence number of the RadioCountToLeds message that is increased
   for each new polling msg [SEQ_NUM]
 - the global time when the polling message arrived [GLOB_TIME]
 - a result_t value indicating if the timestamp is valid [IS_TIME_VALID]
   (a result_t of 0 denotes a valid timestamp)

If the application is running correctly, then the output should show
reports from the different FTSP nodes with valid timestamps and similar
global time values. For example, this is a trace with two FTSP nodes,
with IDs 1 and 5:

1214516486569 1 10916 433709 0
1214516486569 5 10916 433709 0
1214516486809 5 10917 433964 0
1214516486809 1 10917 433963 0
1214516487045 5 10918 434210 0
1214516487053 1 10918 434210 0
1214516487285 1 10919 434454 0
1214516487293 5 10919 434455 0

One way to test if FTSP is operating correctly is to turn off one of
the FTSP nodes. For a short time, that node's global times will differ
significantly and its valid flag will not be 0. For example, this
is what it looks like when node 1 in the earlier trace is reset:

1214516490953 5 10934 438208 0
1214516491201 5 10935 438460 0
1214516491441 5 10936 438712 0
1214516491685 5 10937 438964 0
1214516492169 5 10939 439455 0
1214516492417 1 10940 243 1
1214516492421 5 10940 439706 0
1214516492665 5 10941 439960 0
1214516492669 1 10941 497 1
1214516492905 5 10942 440213 0
...
1214516497541 1 10961 5495 1
1214516497549 5 10961 444958 0
1214516497793 1 10962 5747 1
1214516498025 1 10963 445456 0
1214516498033 5 10963 445455 0
1214516498277 5 10964 445705 0
1214516498285 1 10964 445707 0
1214516498521 1 10965 445964 0

This output is also saved in a file named 'current_timestamp.report'.
'.report' files can be used with the FtspDataAnalyzer.m Matlab
application. Mean absolute timesync error, global time, and % of
synced motes will be plotted.

--- NEW FILE: TestFtsp.h ---
/*
 * Copyright (c) 2002, Vanderbilt University
 * 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 VANDERBILT UNIVERSITY 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 VANDERBILT
 * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * THE VANDERBILT UNIVERSITY 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 VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * @author: Miklos Maroti, Brano Kusy (kusy at isis.vanderbilt.edu)
 * Ported to T2: 3/17/08 by Brano Kusy (branislav.kusy at gmail.com)
 */

#ifndef TEST_FTSP_H
#define TEST_FTSP_H

typedef nx_struct test_ftsp_msg
{
  nx_uint16_t    src_addr;
  nx_uint16_t    counter;
  nx_uint32_t    local_rx_timestamp;
  nx_uint32_t    global_rx_timestamp;
  nx_int32_t     skew_times_1000000;
  nx_uint8_t     is_synced;
  nx_uint16_t    ftsp_root_addr;
  nx_uint8_t     ftsp_seq;
  nx_uint8_t     ftsp_table_entries;
} test_ftsp_msg_t;

enum
{
	AM_TEST_FTSP_MSG = 137
};

#endif

--- NEW FILE: TestFtspAppC.nc ---
/*
 * Copyright (c) 2002, Vanderbilt University
 * 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 VANDERBILT UNIVERSITY 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 VANDERBILT
 * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * THE VANDERBILT UNIVERSITY 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 VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * @author: Miklos Maroti, Brano Kusy (kusy at isis.vanderbilt.edu)
 * Ported to T2: 3/17/08 by Brano Kusy (branislav.kusy at gmail.com)
 */

#include "TestFtsp.h"
#include "RadioCountToLeds.h"

configuration TestFtspAppC {
}

implementation {
  components MainC, TimeSyncC;

  MainC.SoftwareInit -> TimeSyncC;
  TimeSyncC.Boot -> MainC;

  components TestFtspC as App;
  App.Boot -> MainC;

  components ActiveMessageC;
  App.RadioControl -> ActiveMessageC;
  App.Receive -> ActiveMessageC.Receive[AM_RADIO_COUNT_MSG];
  App.AMSend -> ActiveMessageC.AMSend[AM_TEST_FTSP_MSG];
  App.Packet -> ActiveMessageC;
  App.PacketTimeStamp -> ActiveMessageC;

  components LedsC;

  App.GlobalTime -> TimeSyncC;
  App.TimeSyncInfo -> TimeSyncC;
  App.Leds -> LedsC;

}

--- NEW FILE: TestFtspC.nc ---
/*
 * Copyright (c) 2002, Vanderbilt University
 * 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 VANDERBILT UNIVERSITY 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 VANDERBILT
 * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * THE VANDERBILT UNIVERSITY 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 VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * @author: Miklos Maroti, Brano Kusy (kusy at isis.vanderbilt.edu)
 * Ported to T2: 3/17/08 by Brano Kusy (branislav.kusy at gmail.com)
 */

#include "TestFtsp.h"
#include "RadioCountToLeds.h"

module TestFtspC
{
    uses
    {
        interface GlobalTime<TMilli>;
        interface TimeSyncInfo;
        interface Receive;
        interface AMSend;
        interface Packet;
        interface Leds;
        interface PacketTimeStamp<TMilli,uint32_t>;
        interface Boot;
        interface SplitControl as RadioControl;
    }
}

implementation
{
    message_t msg;
    bool locked = FALSE;

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

    event message_t* Receive.receive(message_t* msgPtr, void* payload, uint8_t len)
    {
        call Leds.led0Toggle();
        if (!locked && call PacketTimeStamp.isValid(msgPtr)) {
            radio_count_msg_t* rcm = (radio_count_msg_t*)call Packet.getPayload(msgPtr, sizeof(radio_count_msg_t));
            test_ftsp_msg_t* report = (test_ftsp_msg_t*)call Packet.getPayload(&msg, sizeof(test_ftsp_msg_t));

            uint32_t rxTimestamp = call PacketTimeStamp.timestamp(msgPtr);

            report->src_addr = TOS_NODE_ID;
            report->counter = rcm->counter;
            report->local_rx_timestamp = rxTimestamp;
            report->is_synced = call GlobalTime.local2Global(&rxTimestamp);
            report->global_rx_timestamp = rxTimestamp;
            report->skew_times_1000000 = (uint32_t)call TimeSyncInfo.getSkew()*1000000UL;
            report->ftsp_root_addr = call TimeSyncInfo.getRootID();
            report->ftsp_seq = call TimeSyncInfo.getSeqNum();
            report->ftsp_table_entries = call TimeSyncInfo.getNumEntries();

            if (call AMSend.send(AM_BROADCAST_ADDR, &msg, sizeof(test_ftsp_msg_t)) == SUCCESS) {
              locked = TRUE;
            }
        }

        return msgPtr;
    }

    event void AMSend.sendDone(message_t* ptr, error_t success) {
        locked = FALSE;
        return;
    }

    event void RadioControl.startDone(error_t err) {}
    event void RadioControl.stopDone(error_t error){}
}



More information about the Tinyos-2-commits mailing list