From 2d01be815a7e72e4d296ea22f65aebd22986e99d Mon Sep 17 00:00:00 2001 From: scipio Date: Wed, 4 Jul 2007 16:15:11 +0000 Subject: [PATCH] Patch that includes source address fields for packet. --- tos/lib/tossim/TOSSIM.py | 2 ++ tos/lib/tossim/packet.c | 7 +++++++ tos/lib/tossim/packet.h | 3 +++ tos/lib/tossim/packet.i | 3 +++ tos/lib/tossim/sim_packet.c | 12 +++++++++++- tos/lib/tossim/sim_packet.h | 3 +++ tos/lib/tossim/tossim_wrap.cxx | 36 ++++++++++++++++++++++++++++++++++ 7 files changed, 65 insertions(+), 1 deletion(-) diff --git a/tos/lib/tossim/TOSSIM.py b/tos/lib/tossim/TOSSIM.py index 32f89e39..38406a8b 100644 --- a/tos/lib/tossim/TOSSIM.py +++ b/tos/lib/tossim/TOSSIM.py @@ -113,6 +113,8 @@ class Packet(_object): try: if self.thisown: destroy(self) except: pass + def setSource(*args): return apply(_TOSSIM.Packet_setSource,args) + def source(*args): return apply(_TOSSIM.Packet_source,args) def setDestination(*args): return apply(_TOSSIM.Packet_setDestination,args) def destination(*args): return apply(_TOSSIM.Packet_destination,args) def setLength(*args): return apply(_TOSSIM.Packet_setLength,args) diff --git a/tos/lib/tossim/packet.c b/tos/lib/tossim/packet.c index 78268585..c90b6c75 100644 --- a/tos/lib/tossim/packet.c +++ b/tos/lib/tossim/packet.c @@ -54,6 +54,13 @@ Packet::~Packet() { } } +void Packet::setSource(int src) { + sim_packet_set_source(msgPtr, (uint16_t)src); +} +int Packet::source() { + return sim_packet_source(msgPtr); +} + void Packet::setDestination(int dest) { sim_packet_set_destination(msgPtr, (uint16_t)dest); } diff --git a/tos/lib/tossim/packet.h b/tos/lib/tossim/packet.h index f59f8c92..6312b6bf 100644 --- a/tos/lib/tossim/packet.h +++ b/tos/lib/tossim/packet.h @@ -40,6 +40,9 @@ class Packet { Packet(sim_packet_t* msg); ~Packet(); + void setSource(int src); + int source(); + void setDestination(int dest); int destination(); diff --git a/tos/lib/tossim/packet.i b/tos/lib/tossim/packet.i index c45f4cbd..f2196181 100644 --- a/tos/lib/tossim/packet.i +++ b/tos/lib/tossim/packet.i @@ -45,6 +45,9 @@ class Packet { public: Packet(); ~Packet(); + + void setSource(int src); + int source(); void setDestination(int dest); int destination(); diff --git a/tos/lib/tossim/sim_packet.c b/tos/lib/tossim/sim_packet.c index e2d97979..d6105e53 100644 --- a/tos/lib/tossim/sim_packet.c +++ b/tos/lib/tossim/sim_packet.c @@ -43,10 +43,20 @@ static tossim_header_t* getHeader(message_t* msg) { return (tossim_header_t*)(msg->data - sizeof(tossim_header_t)); } +void sim_packet_set_source(sim_packet_t* msg, uint16_t src)__attribute__ ((C, spontaneous)) { + tossim_header_t* hdr = getHeader((message_t*)msg); + hdr->src = src; +} + +uint16_t sim_packet_source(sim_packet_t* msg)__attribute__ ((C, spontaneous)) { + tossim_header_t* hdr = getHeader((message_t*)msg); + return hdr->src; +} + void sim_packet_set_destination(sim_packet_t* msg, uint16_t dest)__attribute__ ((C, spontaneous)) { tossim_header_t* hdr = getHeader((message_t*)msg); hdr->dest = dest; -}__attribute__ ((C, spontaneous)) +} uint16_t sim_packet_destination(sim_packet_t* msg)__attribute__ ((C, spontaneous)) { tossim_header_t* hdr = getHeader((message_t*)msg); diff --git a/tos/lib/tossim/sim_packet.h b/tos/lib/tossim/sim_packet.h index 392ad49d..d0643e6a 100644 --- a/tos/lib/tossim/sim_packet.h +++ b/tos/lib/tossim/sim_packet.h @@ -50,6 +50,9 @@ extern "C" { */ typedef struct sim_packet {} sim_packet_t; + void sim_packet_set_source(sim_packet_t* msg, uint16_t src); + uint16_t sim_packet_source(sim_packet_t* msg); + void sim_packet_set_destination(sim_packet_t* msg, uint16_t dest); uint16_t sim_packet_destination(sim_packet_t* msg); diff --git a/tos/lib/tossim/tossim_wrap.cxx b/tos/lib/tossim/tossim_wrap.cxx index ab6fecb3..92c30d10 100644 --- a/tos/lib/tossim/tossim_wrap.cxx +++ b/tos/lib/tossim/tossim_wrap.cxx @@ -1504,6 +1504,40 @@ static PyObject *_wrap_delete_Packet(PyObject *self, PyObject *args) { } +static PyObject *_wrap_Packet_setSource(PyObject *self, PyObject *args) { + PyObject *resultobj; + Packet *arg1 = (Packet *) 0 ; + int arg2 ; + PyObject * obj0 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"Oi:Packet_setSource",&obj0,&arg2)) goto fail; + if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_Packet,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; + (arg1)->setSource(arg2); + + Py_INCREF(Py_None); resultobj = Py_None; + return resultobj; + fail: + return NULL; +} + + +static PyObject *_wrap_Packet_source(PyObject *self, PyObject *args) { + PyObject *resultobj; + Packet *arg1 = (Packet *) 0 ; + int result; + PyObject * obj0 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"O:Packet_source",&obj0)) goto fail; + if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_Packet,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; + result = (int)(arg1)->source(); + + resultobj = PyInt_FromLong((long)result); + return resultobj; + fail: + return NULL; +} + + static PyObject *_wrap_Packet_setDestination(PyObject *self, PyObject *args) { PyObject *resultobj; Packet *arg1 = (Packet *) 0 ; @@ -3322,6 +3356,8 @@ static PyMethodDef SwigMethods[] = { { (char *)"Radio_swigregister", Radio_swigregister, METH_VARARGS }, { (char *)"new_Packet", _wrap_new_Packet, METH_VARARGS }, { (char *)"delete_Packet", _wrap_delete_Packet, METH_VARARGS }, + { (char *)"Packet_setSource", _wrap_Packet_setSource, METH_VARARGS }, + { (char *)"Packet_source", _wrap_Packet_source, METH_VARARGS }, { (char *)"Packet_setDestination", _wrap_Packet_setDestination, METH_VARARGS }, { (char *)"Packet_destination", _wrap_Packet_destination, METH_VARARGS }, { (char *)"Packet_setLength", _wrap_Packet_setLength, METH_VARARGS }, -- 2.39.2