hi All ,
i am re-posting this mail for help.
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 need your help...
actually iam tryng to flood a message to nodes in tossim , in which i have
injected packet containing location(coordinate) of the nodes. i am able to
inject packet to each node on the network, but while i am going to send a
message, its giving segmentation fault.plz hep.
*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,
sizeof(req_Msg)));
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)
*
output*
$ python test.py
DEBUG (0): system booted.
DEBUG (0): AMControl started.
DEBUG (1): system booted.
DEBUG (1): AMControl started.
DEBUG (2): system booted.
DEBUG (2): AMControl started.
DEBUG (3): system booted.
DEBUG (3): AMControl started.
DEBUG (4): system booted.
DEBUG (4): AMControl started.
DEBUG (5): system booted.
DEBUG (5): AMControl started.
DEBUG (6): system booted.
DEBUG (6): AMControl started.
DEBUG (7): system booted.
DEBUG (7): AMControl started.
DEBUG (8): system booted.
DEBUG (8): AMControl started.
DEBUG (9): system booted.
DEBUG (9): AMControl started.
Delivering Message <coordinateMsg>
[x=0x9d2]
[y=0x116a]
[sinkx=0x11c8]
[sinky=0x159c]
to 0 at 9000000383
Delivering Message <coordinateMsg>
[x=0xfcf]
[y=0x2208]
[sinkx=0x11c8]
[sinky=0x159c]
to 1 at 9000000383
Delivering Message <coordinateMsg>
[x=0x2265]
[y=0x64f]
[sinkx=0x11c8]
[sinky=0x159c]
to 2 at 9000000383
Delivering Message <coordinateMsg>
[x=0x661]
[y=0xc80]
[sinkx=0x11c8]
[sinky=0x159c]
to 3 at 9000000383
Delivering Message <coordinateMsg>
[x=0x997]
[y=0x1eaf]
[sinkx=0x11c8]
[sinky=0x159c]
to 4 at 9000000383
Delivering Message <coordinateMsg>
[x=0x11c8]
[y=0x159c]
[sinkx=0x11c8]
[sinky=0x159c]
to 5 at 9000000383
Delivering Message <coordinateMsg>
[x=0x2680]
[y=0x11c1]
[sinkx=0x11c8]
[sinky=0x159c]
to 6 at 9000000383
Delivering Message <coordinateMsg>
[x=0x19bd]
[y=0x1d66]
[sinkx=0x11c8]
[sinky=0x159c]
to 7 at 9000000383
Delivering Message <coordinateMsg>
[x=0x16d5]
[y=0x19b9]
[sinkx=0x11c8]
[sinky=0x159c]
to 8 at 9000000383
Delivering Message <coordinateMsg>
[x=0x5f4]
[y=0x19bb]
[sinkx=0x11c8]
[sinky=0x159c]
to 9 at 9000000383
DEBUG (0): Received packet length is 16.
DEBUG (0): x is 25.139999 & y is 44.580002. & r is 2303.675293
sinkx is 45.520000 & sinky is 55.320000
DEBUG (0): timer
DEBUG (1): Received packet length is 16.
DEBUG (1): x is 40.470001 & y is 87.120003. & r is 3219.849121
sinkx is 45.520000 & sinky is 55.320000
DEBUG (5): Received packet length is 16.
DEBUG (5): x is 45.520000 & y is 55.320000. & r is 0.000000
sinkx is 45.520000 & sinky is 55.320000
DEBUG (7): Received packet length is 16.
DEBUG (7): x is 65.889999 & y is 75.260002. & r is 2850.509766
sinkx is 45.520000 & sinky is 55.320000
DEBUG (8): Received packet length is 16.
DEBUG (8): x is 58.450001 & y is 65.849998. & r is 1667.530396
sinkx is 45.520000 & sinky is 55.320000
DEBUG (6): Received packet length is 16.
DEBUG (6): x is 98.559998 & y is 45.450001. & r is 5395.051758
sinkx is 45.520000 & sinky is 55.320000
DEBUG (2): Received packet length is 16.
DEBUG (2): x is 88.050003 & y is 16.150000. & r is 5781.946289
sinkx is 45.520000 & sinky is 55.320000
DEBUG (3): Received packet length is 16.
DEBUG (3): x is 16.330000 & y is 32.000000. & r is 3736.145752
sinkx is 45.520000 & sinky is 55.320000
DEBUG (4): Received packet length is 16.
DEBUG (4): x is 24.549999 & y is 78.550003. & r is 3129.495117
sinkx is 45.520000 & sinky is 55.320000
DEBUG (9): Received packet length is 16.
DEBUG (9): x is 15.240000 & y is 65.870003. & r is 3206.526123
sinkx is 45.520000 & sinky is 55.320000
DEBUG (0): Timer is started.
DEBUG (0): packet open.
DEBUG (0): Sending..
*Segmentation fault (core dumped)*
I am total confusing why this error is happening.
thank you again.
any suggestion regarding this problem also apprciated.
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help