[Tinyos-help] 'EasyBroadcast' problem

Jordan Jan Jordanow jordanow at wp.eu
Fri Jun 6 04:28:52 PDT 2008


Hello * ,
 
    I wrote a little program named 'EasyBroadcast' that should send a 
message every 2 second to the base station with incrementing values. 
Base station is a node with ID=1. Base station forwards received packets 
to serial. The problem is when I read this message with MsgReader I only 
get:
1212743018886: Message <EasyBroadcastMsg>
[nodeid = 0x00]
[xValue=0x0]
[yValue=0x0]

I checked with printf if the message I sent to serial contains right 
data  :
 --------
from node: 5
xv: 6
yv: 18
--------

So obvious the data is right. But serial gets 'null' values.
_____________________________________________________________-
My code :
EasyBroadcastC.nc

#include <Timer.h>
#include "printf.h"
#include "EasyBroadcast.h"

module EasyBroadcastC {
	uses{
	 interface Boot;
	 interface SplitControl as SerialControl;
	 interface SplitControl as RadioControl;
	 interface StdControl as RoutingControl;
	 interface Packet as RadioPacket;
	 interface Packet as SerialPacket;
	 interface AMSend;
	 interface Send;
	 interface Leds;
	 interface Timer<TMilli>;
	 interface RootControl;
	 interface Receive;
	 interface SplitControl as PrintfControl;
	 interface PrintfFlush;
	}
}
implementation {
	message_t packet;
	bool sendBusy = FALSE;
	uint8_t xCounter = 0;
	uint8_t yCounter = 0;

	event void Boot.booted() {
		call PrintfControl.start();
		call RadioControl.start();
	}
	event void RadioControl.startDone(error_t err) {
		if (err == !SUCCESS) {
			call RadioControl.start();
		}else {
			call RoutingControl.start();
			if ( TOS_NODE_ID ==1 ){
				call SerialControl.start();
				call RootControl.setRoot();
			}else{
 				call Timer.startPeriodic(2000);
			}
		}
	}
	void sendMessage() {
		EasyBroadcastMsg* msg = (EasyBroadcastMsg*)(call 
RadioPacket.getPayload(&packet,NULL));
		msg -> nodeid = TOS_NODE_ID;
		msg -> xValue = xCounter;
		msg -> yValue = yCounter;
		if (call Send.send(&packet, sizeof(EasyBroadcastMsg)) == SUCCESS)
			sendBusy = TRUE;
		else
			call Leds.led0On();
	}
	void forwardMessage(message_t* m) {
		call AMSend.send(AM_BROADCAST_ADDR,&newPacket, 
sizeof(EasyBroadcastMsg));
		//EasyBroadcastMsg* msg;
		//call AMSend.send(AM_BROADCAST_ADDR,m, sizeof(EasyBroadcastMsg));
		/*printf("from node: %d\n",msg -> nodeid);
		printf("xv: %d\n",msg -> xValue);
		printf("yv: %d\n",msg -> yValue);
		printf("--------\n");
		call PrintfFlush.flush();*/
	}
	event void Timer.fired() {
		call Leds.led2Toggle();
		if (!sendBusy){
			xCounter++;
			yCounter +=3;
			sendMessage();
		}
	}
	event void Send.sendDone (message_t* m, error_t err) {
		if (err != SUCCESS)
			call Leds.led0Toggle();
		sendBusy = FALSE;
	}
	event void AMSend.sendDone(message_t* bufPtr, error_t error) {
    		if (error == SUCCESS)
			call Leds.led2Toggle();
  	}
	event message_t * Receive.receive(message_t* msg, void * payload, 
uint8_t len) {
		call Leds.led1Toggle();
		forwardMessage(msg);
		return msg;
	}
	event void PrintfControl.startDone(error_t error) {}
	event void PrintfControl.stopDone(error_t error) {}
	event void PrintfFlush.flushDone(error_t error) {}
	event void RadioControl.stopDone(error_t err) {}
	event void SerialControl.startDone(error_t err) {}
	event void SerialControl.stopDone(error_t err) {}
}
EasyBroadcastAppC.nc
configuration EasyBroadcastAppC {}
implementation {
	components EasyBroadcastC, MainC, LedsC, ActiveMessageC;
	components CollectionC as Collector;
	components new CollectionSenderC(AM_EASYBROADCASTMSG);
	components SerialActiveMessageC as AM;
	components new TimerMilliC();
	components PrintfC;

	EasyBroadcastC.Boot -> MainC;
	EasyBroadcastC.Leds -> LedsC;
	EasyBroadcastC.Timer -> TimerMilliC;
	EasyBroadcastC.SerialControl -> AM;
	EasyBroadcastC.RadioControl -> ActiveMessageC;
	EasyBroadcastC.RoutingControl -> Collector;
	EasyBroadcastC.AMSend -> AM.AMSend[AM_EASYBROADCASTMSG];
	EasyBroadcastC.Send -> CollectionSenderC;
	EasyBroadcastC.RadioPacket -> CollectionSenderC.Packet;
	EasyBroadcastC.SerialPacket -> AM.Packet;
	EasyBroadcastC.RootControl -> Collector;
	EasyBroadcastC.Receive -> Collector.Receive[AM_EASYBROADCASTMSG];
	EasyBroadcastC.PrintfControl-> PrintfC;
	EasyBroadcastC.PrintfFlush -> PrintfC;

}
EasyBroadcast.h
#ifndef EASYBROADCAST_H
#define EASYBROADCAST_H
enum {
	TIMER_PERIOD_MILLI = 2000,
	AM_EASYBROADCASTMSG = 6
};
typedef nx_struct EasyBroadcastMsg {
	nx_uint8_t nodeid;
	nx_uint8_t xValue;
	nx_uint8_t yValue;
} EasyBroadcastMsg;
#endif

__________________________________________________________________

It's probably some stupid error in reasoning but I would be grateful for 
help.

Jordan Jordanow

----------------------------------------------------
Kupujesz auto lub mieszkanie? 
Sprawdź hipotekę i rejestr zastawów. 
Odpisy dostarczymy Ci do domu!  
http://klik.wp.pl/?adr=www.krs.wp.pl&sid=380




More information about the Tinyos-help mailing list