[Tinyos-2-commits] CVS: tinyos-2.x/apps/tests/rf230/TestMac Makefile, NONE, 1.1 TestMac.h, NONE, 1.1 TestMacC.nc, NONE, 1.1 TestMacP.nc, NONE, 1.1

Janos Sallai sallai at users.sourceforge.net
Tue Nov 6 11:41:31 PST 2007


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

Added Files:
	Makefile TestMac.h TestMacC.nc TestMacP.nc 
Log Message:
added rf230 test applications for the IRIS mote

--- NEW FILE: Makefile ---
COMPONENT=TestMacC
CFLAGS += -I$(TOSDIR)/lib/diagmsg
IEEE154_CHANNEL ?= 11
CFLAGS += -DCC240_DEF_CHANNEL=$(IEEE154_CHANNEL)
CFLAGS += -DRF230_DEF_CHANNEL=$(IEEE154_CHANNEL)
CFLAGS += -DRF230_DEBUG
include $(MAKERULES)

--- NEW FILE: TestMac.h ---
/*
 * Copyright (c) 2007, 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
 */

#ifndef __TESTMAC_H__
#define __TESTMAC_H__

/**
 * SEND_RATE the rate in milliseconds a source message should be sent out,
 * if this value is 0, then the message is sent from a task as fast as it can.
 * Set this value to -1 for turning off source messages.
 *
 * SEND_SOURCE the id of the source message. Each ping message contains a source
 * identifier and a sequence number. 
 *
 * SEND_TARGET the active message address of the source messages sent out by 
 * this node. Use AM_BROADCAST_ADDR to broadcast the message.
 *
 * SEND_ACK if it is set to 1, then packet acknowledgements are requested,
 * otherwise set it to 0
 *
 * SOURCE_COUNT the number of data sources in the network whose progress we 
 * need to monitor.
 */

// everybody transmit as fast as we can for up to five nodes with IDs 0 through 4
#if TESTCASE == 0
#define SOURCE_COUNT	5
#define SEND_TARGET		AM_BROADCAST_ADDR
#define SEND_SOURCE		TOS_NODE_ID
#define SEND_RATE		0
#define SEND_ACK		1

// one node sending message to another as fast as it can
#elif TESTCASE == 1
#define SOURCE_COUNT	2
#define SEND_TARGET		1
#define SEND_SOURCE		(TOS_NODE_ID == 0 ? 0 : -1)
#define SEND_RATE		(TOS_NODE_ID == 0 ? 0 : -1)
#define SEND_ACK		1

// two nodes sending messages to one another 200 msgs per second
#elif TESTCASE == 2
#define SOURCE_COUNT	2
#define SEND_TARGET		((TOS_NODE_ID+1) % SOURCE_COUNT)
#define SEND_SOURCE		TOS_NODE_ID
#define SEND_RATE		5
#define SEND_ACK		1

// two nodes sending messages to one another as fast as they can
#elif TESTCASE == 3
#define SOURCE_COUNT	2
#define SEND_TARGET		((TOS_NODE_ID+1) % SOURCE_COUNT)
#define SEND_SOURCE		TOS_NODE_ID
#define SEND_RATE		0
#define SEND_ACK		1

// three nodes sending messages to one another as fast as they can
#elif TESTCASE == 4
#define SOURCE_COUNT	3
#define SEND_TARGET		((TOS_NODE_ID+1) % SOURCE_COUNT)
#define SEND_SOURCE		TOS_NODE_ID
#define SEND_RATE		0
#define SEND_ACK		1

#endif

#endif//__TESTMAC_H__

--- NEW FILE: TestMacC.nc ---
/*
 * Copyright (c) 2007, 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
 */

configuration TestMacC
{
}

implementation
{
	components MainC, TestMacP, DiagMsgC;
	components ActiveMessageC, SerialActiveMessageC;
	components new TimerMilliC() as SendTimerC;
	components new TimerMilliC() as ReportTimerC;

	TestMacP.Boot -> MainC;
	TestMacP.DiagMsg -> DiagMsgC;
	TestMacP.SendTimer -> SendTimerC;
	TestMacP.ReportTimer -> ReportTimerC;

	TestMacP.SerialControl -> SerialActiveMessageC;
	TestMacP.RadioControl -> ActiveMessageC;

	TestMacP.PacketAcknowledgements -> ActiveMessageC;
	TestMacP.AMSend -> ActiveMessageC.AMSend[0x17];
	TestMacP.Receive -> ActiveMessageC.Receive[0x17];
	TestMacP.Snoop -> ActiveMessageC.Snoop[0x17];
}

--- NEW FILE: TestMacP.nc ---
/*
 * Copyright (c) 2007, 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
 */

#include "TestMac.h"

module TestMacP
{
	uses
	{
		interface Boot;
		interface DiagMsg;

		interface Timer<TMilli> as SendTimer;
		interface Timer<TMilli> as ReportTimer;

		interface Receive;
		interface Receive as Snoop;
		interface AMSend;
		interface PacketAcknowledgements;

		interface SplitControl as SerialControl;
		interface SplitControl as RadioControl;
	}
}

implementation
{
	task void serialPowerUp()
	{
		if( call SerialControl.start() != SUCCESS )
			post serialPowerUp();
	}

	event void Boot.booted()
	{
		post serialPowerUp();
	}

	task void radioPowerUp()
	{
		if( call RadioControl.start() != SUCCESS )
			post radioPowerUp();
	}

	event void SerialControl.startDone(error_t error)
	{
		if( error != SUCCESS )
			post serialPowerUp();
		else
			post radioPowerUp();
	}

	void send();

	task void sendTask()
	{
		send();
	}

	event void RadioControl.startDone(error_t error)
	{
		if( error != SUCCESS )
			post radioPowerUp();
		else
		{
			if( SEND_RATE > 0 )
				call SendTimer.startPeriodic(SEND_RATE);
			else if( SEND_RATE == 0 )
				post sendTask();
			
			call ReportTimer.startPeriodic(1000);
		}
	}

	event void SendTimer.fired()
	{
		send();
	}

	event void RadioControl.stopDone(error_t error)	{ }
	event void SerialControl.stopDone(error_t error) { }

	typedef struct source_t
	{
		uint16_t sequence;
		uint16_t failures;
		uint16_t errors;
	} source_t;

	source_t sources[SOURCE_COUNT];

	message_t txMsg;

	typedef struct source_msg_t
	{
		uint8_t source;
		uint16_t sequence;
		uint8_t failures;
		uint8_t errors;
		uint8_t stuff[23];
	} source_msg_t;

	void send()
	{
		source_msg_t* data = (source_msg_t*)txMsg.data;
		data->source = SEND_SOURCE;
		data->sequence = sources[SEND_SOURCE].sequence;
		data->failures = sources[SEND_SOURCE].failures;
		data->errors = sources[SEND_SOURCE].errors;

		if( SEND_ACK )
			call PacketAcknowledgements.requestAck(&txMsg);
		else
			call PacketAcknowledgements.noAck(&txMsg);

		if( call AMSend.send(SEND_TARGET, &txMsg, sizeof(source_msg_t)) != SUCCESS )
			post sendTask();
	}

	event void AMSend.sendDone(message_t* msg, error_t error)
	{
		if( error != SUCCESS )
		{
			sources[SEND_SOURCE].errors += 1;
			post sendTask();
		}
		else
		{
			if( SEND_ACK )
			{
				if( ! call PacketAcknowledgements.wasAcked(msg) )
					sources[SEND_SOURCE].failures += 1;
			}

			sources[SEND_SOURCE].sequence += 1;

			if( SEND_RATE == 0 )
				post sendTask();
		}
	}

	event void ReportTimer.fired()
	{
		if( call DiagMsg.record() )
		{
			uint8_t i;

			call DiagMsg.uint8(TOS_NODE_ID);

			for(i = 0; i < SOURCE_COUNT; ++i)
			{
				call DiagMsg.uint16(sources[i].sequence);
				call DiagMsg.uint16(sources[i].failures);
				call DiagMsg.uint16(sources[i].errors);
			}

			call DiagMsg.send();
		}
	}

	message_t* receive(message_t* msg)
	{
		source_msg_t* data = (source_msg_t*)(msg->data);

		if( data->source < SOURCE_COUNT && data->source != SEND_SOURCE )
		{
			uint8_t source = data->source;

			if( sources[source].sequence == data->sequence )
				sources[source].errors += 1;
			else 
				sources[source].failures += (uint16_t)(data->sequence - sources[source].sequence - 1);

			sources[source].sequence = data->sequence;
		}

		return msg;
	}

	event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len)
	{
		return receive(msg);
	}

	event message_t* Snoop.receive(message_t* msg, void* payload, uint8_t len)
	{
		return receive(msg);
	}
}



More information about the Tinyos-2-commits mailing list