hi all,
i dont able to understand why this code giving error
*injectPac.h*
#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_t;
typedef nx_struct req_Msg{
nx_uint32_t s_id;
nx_uint32_t d_id;
nx_uint32_t dist;
} req_Msg_t;
enum{
AM_COORDINATE_MSG = 1,
AM_REQ_PKT = 2,
};
#endif
*injectpacC.nc*
#include "InjectPac.h"
#include "Timer.h"
#include "math.h"
module InjectPacC {
uses {
interface Boot;
interface Receive;
interface AMSend;
interface SplitControl as AMControl;
interface Packet;
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;
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 AMSend.sendDone(message_t* bfrptr, error_t err){
}
event void AMControl.stopDone(error_t err){
//do nothing
}
event message_t* Receive.receive(message_t* bfrptr, void* payload,
uint8_t len){
dbg("inject","Received packe length is %hhu.\n",len);
if(len != sizeof(coordinate_msg_t)){
return bfrptr;
}
else{
coordinate_msg_t* cor = (coordinate_msg_t*)payload;
x=cor->x;
y=cor->y;
sx=cor->sinkx;
sx=sx/100;
sy=cor->sinky;
sy=sy/100;
x=x/100;
y=y/100;
r=pow((sx-x),2)+pow((sy-y),2);
r=sqrt(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){
if(!busy){
req_Msg_t* rp = (req_Msg_t*) (call
ReqPkt.getPayload(&requestpkt, NULL));
rp -> s_id = TOS_NODE_ID;
rp-> d_id = did;
rp-> dist = r;
if(call SendRequest.send(AM_BROADCAST_ADDR,
&requestpkt, sizeof(req_Msg_t)) == SUCCESS){
busy= TRUE;
}
}
}
}
}
event void SendRequest.sendDone(message_t* msg, error_t err){
dbg("inject","req msg delivered");
}
event message_t* ReceiveRequest.receive(message_t* msg, void* payload,
uint8_t len){
return msg;
}
}
*injectAppC.nc*
#include "InjectPac.h"
configuration InjectPacAppC{
}
implementation{
components MainC;
components InjectPacC as App;
components new AMSenderC(AM_COORDINATE_MSG) as coordinateSend;
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.Receive -> coordinateReceive;
App.AMSend -> coordinateSend;
App.AMControl -> ActiveMessageC;
App.Packet -> coordinateSend;
App.SendRequest -> RequestSender;
App.ReceiveRequest -> RequestReceiver;
App.ReqPkt -> RequestSender;
App.ReqAMPacket -> RequestSender;
}
and i have simulating this code by following .py code*
trst.py*
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(msg.get_amType())
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(2000):
t.runNextEvent()
*but it giving error like below*
$ python test.py
Traceback (most recent call last):
File "test.py", line 3, in ?
from coordinateMsg import *
File "/opt/tinyos-2.x/rajesh/data_rbmd1/coordinateMsg.py", line 34
s += " [nx_struct coordinateMsg 16 -1
^
SyntaxError: EOL while scanning single-quoted string
i am not able to understand 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