hi,
i am getting segmentation fault while i am simulating below code in tossim,
but i cant able to understand why?? . my work has been stop for last 3
weeks, plz help...
actually iam tryng to flood a message to nodes in tossim , in which i have
injected packet containing location(coordinate) of the nodes.
*injectPac.h contain*
#ifndef INJECT_PAC_H
#define INJECT_PAC_H
typedef nx_struct coordinateMsg{
nx_uint32_t x;
nx_uint32_t y;
nx_uint32_t sinkx;
nx_uint32_t sinky;
}coordinate_msg;
typedef nx_struct req_Msg{
nx_uint16_t sid;
nx_uint16_t did;
nx_uint16_t dist;
} req_Msg;
enum{
AM_COORDINATE_MSG = 1,
AM_REQ_PKT = 2,
};
#endif
*injectPacAppC.nc contain*
#include "InjectPac.h"
#include <Timer.h>
#include "math.h"
configuration InjectPacAppC{
}
implementation{
components MainC;
components InjectPacC as App;
components new TimerMilliC() as Timer0;
components new AMReceiverC(AM_COORDINATE_MSG) as coordinateReceive;
components new AMSenderC(AM_REQ_PKT) as RequestSender;
components new AMReceiverC(AM_REQ_PKT) as RequestReceiver;
components ActiveMessageC;
App.Boot -> MainC.Boot;
App.Timer0 -> Timer0;
App.AMControl -> ActiveMessageC;
App.corReceive-> coordinateReceive;
App.corPacket -> coordinateReceive;
App.corAMPacket -> coordinateReceive;
App.ReqAMPacket -> RequestSender;
App.SendRequest -> RequestSender;
App.ReceiveRequest -> RequestReceiver;
App.ReqPkt -> RequestSender;
}
*injectPaC.nc contain*
#include "InjectPac.h"
#include <Timer.h>
#include "math.h"
module InjectPacC {
uses {
interface Boot;
interface Timer<TMilli> as Timer0;
interface Receive as corReceive;
interface SplitControl as AMControl;
interface Packet as corPacket;
interface AMPacket as corAMPacket;
interface AMSend as SendRequest;
interface Packet as ReqPkt;
interface AMPacket as ReqAMPacket;
interface Receive as ReceiveRequest;
}
}
implementation {
bool locked;
float x,y,r,sx,sy,dist;
bool busy=FALSE;
int did=5,rp;
message_t requestpkt;
event void Boot.booted(){
call AMControl.start();
dbg("inject","system booted.\n");
}
event void AMControl.startDone(error_t err){
if(err ==SUCCESS){
dbg("inject","AMControl started.\n");
}
else{
call AMControl.start();
}
}
event void AMControl.stopDone(error_t err){
//do nothing
}
event message_t* corReceive.receive(message_t* bfrptr, void* payload,
uint8_t len){
dbg("inject","Received packet length is %hhu.\n",len);
if(len != sizeof(coordinate_msg)){
return bfrptr;
}
else{
coordinate_msg* cor = (coordinate_msg*)payload;
x=cor->x;
y=cor->y;
sx=cor->sinkx;
sy=cor->sinky;
sx=sx/100;
sy=sy/100;
x=x/100;
y=y/100;
r=pow((sx-x),2)+pow((sy-y),2);
r=sqrt(r);
r=r*100;
rp=r;
dbg("inject","x is %f & y is %f. & r is %f\nsinkx is %f &
sinky is %f\n",x,y,r,sx,sy);
if(TOS_NODE_ID == 0){
call Timer0.startOneShot(200);
dbg("inject","timer\n");
}
}
}
event void Timer0.fired() {
dbg("inject","Timer is started.\n");
if(!busy){
req_Msg* rm =
(req_Msg*) (call ReqPkt.getPayload(&requestpkt, NULL));
dbg("inject","packet open.\n");
rm -> sid = TOS_NODE_ID;
rm -> did = TOS_NODE_ID;
rm -> dist = TOS_NODE_ID;
dbg("inject","Sending..\n");
* if(call SendRequest.send(AM_BROADCAST_ADDR, &requestpkt,
sizeof(req_Msg)) == SUCCESS){*
busy= TRUE;
}
}
}
event void SendRequest.sendDone(message_t* msg, error_t err){
if(&requestpkt == msg){
busy = FALSE;
dbg("inject","req msg delivered");
}
}
event message_t* ReceiveRequest.receive(message_t* msg, void* payload,
uint8_t len){
dbg("inject","%d node receive the msg",TOS_NODE_ID);
return msg;
}
}
*
simulation file test.py contain*
import sys
from TOSSIM import *
from coordinateMsg import *
t = Tossim([])
m = t.mac()
r = t.radio()
t.addChannel("inject", sys.stdout)
for i in range(0, 4):
m = t.getNode(i)
m.bootAtTime((31 + t.ticksPerSecond() / 10) * i + 1)
f = open("topo.txt", "r")
for line in f:
s = line.split()
if s:
if s[0] == "gain":
r.add(int(s[1]), int(s[2]), float(s[3]))
noise = open("meyer-heavy.txt", "r")
for line in noise:
s = line.strip()
if s:
val = int(s)
for i in range(4):
t.getNode(i).addNoiseTraceReading(val)
for i in range(4):
t.getNode(i).createNoiseModel()
for i in range(60):
t.runNextEvent()
sx = 4552
sy = 5532
data=open("coordinate.txt","r")
for line in data:
k=line.split()
msg = coordinateMsg()
dest=int(k[0])
msg.set_x(int(k[1]))
msg.set_y(int(k[2]))
msg.set_sinkx(int(sx));
msg.set_sinky(int(sy));
pkt = t.newPacket()
pkt.setData(msg.data)
pkt.setType(1)
pkt.setDestination(dest)
print "Delivering " + str(msg) + " to "+str(dest)+" at "+ str(t.time()
+ 3);
pkt.deliver(dest, t.time() - 40)
for i in range(10000000):
t.runNextEvent()
*
Makefile contain*
COMPONENT=InjectPacAppC
BUILD_EXTRA_DEPS=coordinateMsg.py
coordinateMsg.py: InjectPac.h
mig python -target=$(PLATFORM) $(CFLAGS)
-python-classname=coordinateMsg InjectPac.h coordinateMsg -o $@
include $(MAKERULES)
I am total confusing why this error is happining.
thanks in advance.
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help