+++ /dev/null
-%load file written out by FtspDataLogger.java class\r
-%arg0 - filename, e.g. '1205543689171.report'\r
-function FTSPDataAnalyzer(file, varargin)\r
-[c1 c2 c3 c4 c5]= textread(file, '%u %u %u %u %u', 'commentstyle', 'shell');\r
-data = [c2 c3 c4 c5]; %skipping the first column (java time)\r
-data1 = sortrows(sortrows(data,1),2);\r
-newdata = [];\r
-\r
-row=1;\r
-newrow=1;\r
-unsynced=0;\r
-while (row<=size(data1,1))\r
-\r
- seqnum=data1(row,2);\r
-\r
- data2=[];\r
- row2=1;\r
- tmprow1=row;\r
- while (row <= size(data1,1) && data1(row,2)==seqnum)\r
- if (data1(row,4)==0)\r
- data2(row2,1)=data1(row,3);\r
- row2= row2+ 1;\r
- else\r
- unsynced=unsynced+1;\r
- end\r
- row = row + 1;\r
- end\r
- \r
- if (row2>1)\r
- row2size=row2-1;\r
- rcvdsize=row-tmprow1;\r
- newdata(newrow,1) = seqnum;\r
- newdata(newrow,2) = mad(data2(1:row2size,1));\r
- newdata(newrow,3) = mean(data2(1:row2size,1));\r
- newdata(newrow,4) = row2size/rcvdsize;\r
- newrow = newrow + 1;\r
- end\r
-end\r
-\r
-if (length(newdata)==0)\r
- disp('no data found (at least one data point from a synchronized mote is required)!');\r
-else\r
- newsize=newrow-1;\r
- subplot(3,1,1);\r
- plot(newdata(1:newsize,1),newdata(1:newsize,2));\r
- title(sprintf('TimeSync Errors'));\r
- subplot(3,1,2);\r
- plot(newdata(1:newsize,1),newdata(1:newsize,3));\r
- title(sprintf('Avg Glob Time'));\r
- subplot(3,1,3);\r
- plot(newdata(1:newsize,1),newdata(1:newsize,4),'b-');\r
- title(sprintf('%% Synced Motes'));\r
-\r
- disp(sprintf('total unsycned num %d (all %d)',unsynced,newsize));\r
- disp(sprintf('avg %0.3f',mean(newdata(1:newsize,2))));\r
- disp(sprintf('max %d',max(newdata(1:newsize,2))));\r
- savedata = newdata(1:newsize,:);\r
- save data.out savedata -ASCII;\r
-end\r
-
\ No newline at end of file
+++ /dev/null
-/* 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();
- }
-}
\ No newline at end of file
+++ /dev/null
-#!/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
+++ /dev/null
-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)
+++ /dev/null
-FtspDataAnalyzer.m\r
-\r
--------------------------------------------------------------------------------\r
-Author/Contact:\r
----------------\r
- Brano Kusy: branislav.kusy@gmail.com\r
-\r
--------------------------------------------------------------------------------\r
-DESCRIPTION:\r
-------------\r
-\r
-FtspDataAnalyzer.m works with data logs collected by FtspDataLogger.java and\r
-calculates the maximum and average timesync error over time.\r
-\r
--------------------------------------------------------------------------------\r
-STEP BY STEP GUIDE TO RUN OUR TEST SCENARIO:\r
---------------------------------------------\r
-1. program and start motes as described in ./README.txt\r
-2. start SerialForwarder and FtspDataLogger.java as described in ./README.txt\r
-3. 'current_time.report' file (where current_time is a number) is created in ./\r
- this file is updated with data in the real time\r
-4. let the experiment run for some time\r
-5. start matlab and enter (assuming your current_time was 1206126224593)\r
- FTSPDataAnalyzer('1206126224593.report')\r
- this will plot the mean absolute timesync error, global time, and number of\r
- synced motes; this can be done while experiment is running\r
-6. Matlab also creates data.out file which contains data in the following format\r
- #seqNum mean_abs_error global_time num_synced_motes\r
- mean_abs_error is calculated as mean absolute deviation from the mean (mad)\r
-\r
-Simulating multi-hop:\r
-1. define TIMESYNC_DEBUG in the Makefile\r
-2. recompile and upload TestFTSP app to n motes with special NODE_IDs:\r
- using 'make micaz reinstall.0xAB', nodes 0xAB and 0xCD can communicate\r
- iff 2D grid coordinates (A,B) and (C,D) are neighbors in a 2D grid\r
- \r
--------------------------------------------------------------------------------\r
-EVALUATION:\r
---------------------------------------------\r
- - deployment setup: 11 nodes in a 5x3 grid using simulated multi-hop (4 points\r
- were vacant as we only used 11 nodes). the max number of hops was 5.\r
- - parameters: sync period 10sec, polling period 3 sec\r
- - experiment length: 100 minutes\r
- - results (1 jiffy is ~30.5 us)\r
- 1.53 jiffy avg error (~50us)\r
- 3.5 jiffy max error (~100us)
\ No newline at end of file
+++ /dev/null
-TestFtsp
-
--------------------------------------------------------------------------------
-Author/Contact:
----------------
- Brano Kusy: branislav.kusy@gmail.com
- Janos Sallai: janos.sallai@vanderbilt.edu
- Miklos Maroti: mmaroti@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.
+++ /dev/null
-/*
- * 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@isis.vanderbilt.edu)
- * Ported to T2: 3/17/08 by Brano Kusy (branislav.kusy@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
+++ /dev/null
-/*
- * 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@isis.vanderbilt.edu)
- * Ported to T2: 3/17/08 by Brano Kusy (branislav.kusy@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;
-
-}
+++ /dev/null
-/*
- * 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@isis.vanderbilt.edu)
- * Ported to T2: 3/17/08 by Brano Kusy (branislav.kusy@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){}
-}