[Tinyos-2-commits]
CVS: tinyos-2.x/tos/lib/tossim CpmModelC.nc, NONE,
1.1 randomlib.c, NONE, 1.1 randomlib.h, NONE,
1.1 ActiveMessageC.nc, 1.4, 1.5 TOSSIM.py, 1.3,
1.4 hashtable.c, 1.2, 1.3 sim_gain.c, 1.3, 1.4 sim_log.c, 1.4,
1.5 sim_mac.c, 1.2, 1.3 sim_noise.c, 1.2, 1.3 sim_noise.h, 1.1,
1.2 sim_tossim.c, 1.4, 1.5 tossim.c, 1.4, 1.5 tossim.h, 1.4,
1.5 tossim.i, 1.3, 1.4 tossim_wrap.cxx, 1.3, 1.4
Phil Levis
scipio at users.sourceforge.net
Sat Mar 31 17:29:38 PDT 2007
Update of /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv27893
Modified Files:
ActiveMessageC.nc TOSSIM.py hashtable.c sim_gain.c sim_log.c
sim_mac.c sim_noise.c sim_noise.h sim_tossim.c tossim.c
tossim.h tossim.i tossim_wrap.cxx
Added Files:
CpmModelC.nc randomlib.c randomlib.h
Log Message:
Add functionality for CPM noise modeling.
--- NEW FILE: CpmModelC.nc ---
/*
* "Copyright (c) 2005 Stanford University. All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose, without fee, and without written
* agreement is hereby granted, provided that the above copyright
* notice, the following two paragraphs and the author appear in all
* copies of this software.
*
* IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* STANFORD UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
* PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND STANFORD UNIVERSITY
* HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
* ENHANCEMENTS, OR MODIFICATIONS."
*/
/**
*
* CPM (closest-pattern matching) is a wireless noise simulation model
* based on statistical extraction from empirical noise data.
* This model provides far more precise
* software simulation environment by exploiting time-correlated noise
* characteristic and shadowing effect as well as path-loss model. For
* details, please refer to the paper
*
* "Improving Wireless Simulation through Noise Modeling." HyungJune
* Lee and Philip Levis, IPSN 2007. You can find a copy at
* http://sing.stanford.edu.
*
* @author Hyungjune Lee, Philip Levis
* @date Oct 12 2006
*/
#include <sim_gain.h>
#include <sim_noise.h>
#include <randomlib.h>
module CpmModelC {
provides interface GainRadioModel as Model;
}
implementation {
message_t* outgoing; // If I'm sending, this is my outgoing packet
bool requestAck;
bool receiving = 0; // Whether or not I think I'm receiving a packet
struct receive_message;
typedef struct receive_message receive_message_t;
struct receive_message {
int source;
sim_time_t start;
sim_time_t end;
double power;
bool lost;
bool ack;
message_t* msg;
receive_message_t* next;
};
receive_message_t* outstandingReceptionHead = NULL;
receive_message_t* allocate_receive_message();
sim_event_t* allocate_receive_event(sim_time_t t, receive_message_t* m);
double timeInMs() {
sim_time_t ftime = sim_time();
int hours, minutes, seconds;
sim_time_t secondBillionths;
int temp_time;
double ms_time;
secondBillionths = (ftime % sim_ticks_per_sec());
if (sim_ticks_per_sec() > (sim_time_t)1000000000) {
secondBillionths /= (sim_ticks_per_sec() / (sim_time_t)1000000000);
}
else {
secondBillionths *= ((sim_time_t)1000000000 / sim_ticks_per_sec());
}
temp_time = (int)(secondBillionths/10000);
if (temp_time % 10 >= 5) {
temp_time += (10-(temp_time%10));
}
else {
temp_time -= (temp_time%10);
}
ms_time = (float)(temp_time/100.0);
seconds = (int)(ftime / sim_ticks_per_sec());
minutes = seconds / 60;
hours = minutes / 60;
seconds %= 60;
minutes %= 60;
ms_time += (hours*3600+minutes*60+seconds)*1000;
return ms_time;
}
//Generate a CPM noise reading
double noise_hash_generation() {
double CT = timeInMs();
uint32_t quotient = ((sim_time_t)(CT*10))/10;
uint8_t remain = (uint8_t)(((sim_time_t)(CT*10))%10);
double noise_val;
uint16_t node_id = sim_node();
dbg("SNIST_1", "IN: noise_hash_generation()\n");
if (5 <= remain && remain < 10) {
noise_val = (double)sim_noise_generate(node_id, quotient+1);
}
else {
noise_val = (double)sim_noise_generate(node_id, quotient);
}
dbg("SNIST_1", "OUT: noise_hash_generation()\n");
return noise_val;
}
double packetSnr(receive_message_t* msg) {
double signalStr = msg->power;
double noise = noise_hash_generation();
return (signalStr - noise);
}
void sim_gain_ack_handle(sim_event_t* evt) {
if (outgoing != NULL && requestAck && sim_mote_is_on(sim_node())) {
signal Model.acked(outgoing);
}
}
sim_event_t receiveEvent;
// This clear threshold comes from the CC2420 data sheet
double clearThreshold = -95.0;
bool collision = FALSE;
message_t* incoming = NULL;
int incomingSource;
command void Model.setClearValue(double value) {
clearThreshold = value;
dbg("SNIST_1", "Setting clear threshold to %f\n", clearThreshold);
}
command bool Model.clearChannel() {
dbg("SNIST_1", "Checking clear channel @ %s: %f <= %f \n", sim_time_string(), (double)noise_hash_generation(), clearThreshold);
return noise_hash_generation() < clearThreshold;
}
void sim_gain_schedule_ack(int source, sim_time_t t) {
sim_event_t* ackEvent = (sim_event_t*)malloc(sizeof(sim_event_t));
ackEvent->mote = source;
ackEvent->force = 1;
ackEvent->cancelled = 0;
ackEvent->time = t;
ackEvent->handle = sim_gain_ack_handle;
ackEvent->cleanup = sim_queue_cleanup_event;
sim_queue_insert(ackEvent);
}
double prr_estimate_from_snr(double SNR) {
double beta1 = 1.3687;
double beta2 = 0.9187;
double SNR_lin = pow(10.0, SNR/10.0);
double X = fabs(SNR_lin-beta2);
double PSE = 0.5*erfc(beta1*sqrt(X/2));
double prr_hat = pow(1-PSE, 23*2);
if (prr_hat > 1)
prr_hat = 1;
else if (prr_hat < 0)
prr_hat = 0;
return prr_hat;
}
bool shouldReceive(double SNR) {
double prr = prr_estimate_from_snr(SNR);
double coin = RandomUniform();
if ( (prr != 0) && (prr != 1) ) {
if (coin < prr)
prr = 1.0;
else
prr = 0.0;
}
return prr;
}
bool checkReceive(receive_message_t* msg) {
double noise = noise_hash_generation();
receive_message_t* list = outstandingReceptionHead;
noise = pow(10.0, noise / 10.0);
while (list != NULL) {
if (list != msg) {
noise += pow(10.0, list->power / 10.0);
}
}
noise = 10.0 * log(noise) / log(10.0);
return shouldReceive(msg->power / noise);
}
double packetNoise(receive_message_t* msg) {
double noise = noise_hash_generation();
receive_message_t* list = outstandingReceptionHead;
noise = pow(10.0, noise / 10.0);
while (list != NULL) {
if (list != msg) {
noise += pow(10.0, list->power / 10.0);
}
}
noise = 10.0 * log(noise) / log(10.0);
return noise;
}
double checkPrr(receive_message_t* msg) {
return prr_estimate_from_snr(msg->power / packetNoise(msg));
}
void sim_gain_receive_handle(sim_event_t* evt) {
receive_message_t* mine = (receive_message_t*)evt->data;
receive_message_t* predecessor = NULL;
receive_message_t* list = outstandingReceptionHead;
dbg("SNIST_1", "Handling reception event @ %s.\n", sim_time_string());
while (list != NULL) {
if (list->next == mine) {
predecessor = list;
}
list = list->next;
}
if (predecessor) {
predecessor->next = mine->next;
}
else if (mine == outstandingReceptionHead) { // must be head
outstandingReceptionHead = mine->next;
}
else {
dbgerror("SNIST", "Incoming packet list structure is corrupted: entry is not the head and no entry points to it.\n");
}
if (!checkReceive(mine)) {
dbg("SNIST", "Lost packet as SNR was too low.\n");
mine->lost = 1;
}
if (!mine->lost) {
dbg_clear("SNIST", " -signaling reception, ");
signal Model.receive(mine->msg);
if (mine->ack) {
dbg_clear("SNIST", " acknowledgment requested, ");
}
else {
dbg_clear("SNIST", " no acknowledgment requested.\n");
}
// If we scheduled an ack, receiving = 0 when it completes
if (mine->ack && signal Model.shouldAck(mine->msg)) {
dbg_clear("SNIST", " scheduling ack.\n");
sim_gain_schedule_ack(mine->source, sim_time() + 1);
}
// We're searching for new packets again
receiving = 0;
} // If the packet was lost, then we're searching for new packets again
else {
receiving = 0;
dbg_clear("SNIST", " -packet was lost.\n");
}
free(mine);
}
// Create a record that a node is receiving a packet,
// enqueue a receive event to figure out what happens.
void enqueue_receive_event(int source, sim_time_t endTime, message_t* msg, bool receive, double power) {
sim_event_t* evt;
receive_message_t* rcv = allocate_receive_message();
double noiseStr = packetNoise(rcv);
rcv->source = source;
rcv->start = sim_time();
rcv->end = endTime;
rcv->power = power;
rcv->msg = msg;
rcv->lost = 0;
rcv->ack = receive;
// If I'm off, I never receive the packet, but I need to keep track of
// it in case I turn on and someone else starts sending me a weaker
// packet. So I don't set receiving to 1, but I keep track of
// the signal strength.
if (!sim_mote_is_on(sim_node())) {
dbg("SNIST", "Lost packet from %i due to %i being off\n", source, sim_node());
rcv->lost = 1;
}
else if (!shouldReceive(power - noiseStr)) {
rcv->lost = 1;
}
else if (receiving) {
rcv->lost = 1;
}
else {
receiving = 1;
rcv->next = outstandingReceptionHead;
outstandingReceptionHead = rcv;
evt = allocate_receive_event(endTime, rcv);
sim_queue_insert(evt);
}
}
void sim_gain_put(int dest, message_t* msg, sim_time_t endTime, bool receive, double power) {
int prevNode = sim_node();
dbg("SNIST_1", "Enqueing reception event for %i at %llu.\n", dest, endTime);
sim_set_node(dest);
enqueue_receive_event(prevNode, endTime, msg, receive, power);
sim_set_node(prevNode);
}
command void Model.putOnAirTo(int dest, message_t* msg, bool ack, sim_time_t endTime, double power) {
gain_entry_t* link = sim_gain_first(sim_node());
requestAck = ack;
outgoing = msg;
dbg("SNIST", "Node %i transmitting to %i, finishes at %llu.\n", sim_node(), dest, endTime);
while (link != NULL) {
int other = link->mote;
sim_gain_put(other, msg, endTime, ack && (other == dest), power);
link = sim_gain_next(link);
}
}
default event void Model.receive(message_t* msg) {}
sim_event_t* allocate_receive_event(sim_time_t endTime, receive_message_t* msg) {
sim_event_t* evt = (sim_event_t*)malloc(sizeof(sim_event_t));
evt->mote = sim_node();
evt->time = endTime;
evt->handle = sim_gain_receive_handle;
evt->cleanup = sim_queue_cleanup_event;
evt->cancelled = 0;
evt->force = 1; // Need to keep track of air even when node is off
evt->data = msg;
return evt;
}
receive_message_t* allocate_receive_message() {
return (receive_message_t*)malloc(sizeof(receive_message_t));
}
}
--- NEW FILE: randomlib.c ---
/*
This Random Number Generator is based on the algorithm in a FORTRAN
version published by George Marsaglia and Arif Zaman, Florida State
University; ref.: see original comments below.
At the fhw (Fachhochschule Wiesbaden, W.Germany), Dept. of Computer
Science, we have written sources in further languages (C, Modula-2
Turbo-Pascal(3.0, 5.0), Basic and Ada) to get exactly the same test
results compared with the original FORTRAN version.
April 1989
Karl-L. Noell <NOELL at DWIFH1.BITNET>
and Helmut Weber <WEBER at DWIFH1.BITNET>
This random number generator originally appeared in "Toward a Universal
Random Number Generator" by George Marsaglia and Arif Zaman.
Florida State University Report: FSU-SCRI-87-50 (1987)
It was later modified by F. James and published in "A Review of Pseudo-
random Number Generators"
THIS IS THE BEST KNOWN RANDOM NUMBER GENERATOR AVAILABLE.
(However, a newly discovered technique can yield
a period of 10^600. But that is still in the development stage.)
It passes ALL of the tests for random number generators and has a period
of 2^144, is completely portable (gives bit identical results on all
machines with at least 24-bit mantissas in the floating point
representation).
The algorithm is a combination of a Fibonacci sequence (with lags of 97
and 33, and operation "subtraction plus one, modulo one") and an
"arithmetic sequence" (using subtraction).
Use IJ = 1802 & KL = 9373 to test the random number generator. The
subroutine RANMAR should be used to generate 20000 random numbers.
Then display the next six random numbers generated multiplied by 4096*4096
If the random number generator is working properly, the random numbers
should be:
6533892.0 14220222.0 7275067.0
6172232.0 8354498.0 10633180.0
*/
/* Globals */
static double u[97],c,cd,cm;
static int i97,j97;
static int test = FALSE;
/*
This is the initialization routine for the random number generator.
NOTE: The seed variables can have values between: 0 <= IJ <= 31328
0 <= KL <= 30081
The random number sequences created by these two seeds are of sufficient
length to complete an entire calculation with. For example, if sveral
different groups are working on different parts of the same calculation,
each group could be assigned its own IJ seed. This would leave each group
with 30000 choices for the second seed. That is to say, this random
number generator can create 900 million different subsequences -- with
each subsequence having a length of approximately 10^30.
*/
void RandomInitialise(int ij,int kl)
{
double s,t;
int ii,i,j,k,l,jj,m;
/*
Handle the seed range errors
First random number seed must be between 0 and 31328
Second seed must have a value between 0 and 30081
*/
if (ij < 0 || ij > 31328 || kl < 0 || kl > 30081) {
ij = 1802;
kl = 9373;
}
i = (ij / 177) % 177 + 2;
j = (ij % 177) + 2;
k = (kl / 169) % 178 + 1;
l = (kl % 169);
for (ii=0; ii<97; ii++) {
s = 0.0;
t = 0.5;
for (jj=0; jj<24; jj++) {
m = (((i * j) % 179) * k) % 179;
i = j;
j = k;
k = m;
l = (53 * l + 1) % 169;
if (((l * m % 64)) >= 32)
s += t;
t *= 0.5;
}
u[ii] = s;
}
c = 362436.0 / 16777216.0;
cd = 7654321.0 / 16777216.0;
cm = 16777213.0 / 16777216.0;
i97 = 97;
j97 = 33;
test = TRUE;
}
/*
This is the random number generator proposed by George Marsaglia in
Florida State University Report: FSU-SCRI-87-50
*/
double RandomUniform(void)
{
double uni;
int seed1, seed2;
/* Make sure the initialisation routine has been called */
if (!test)
{
#if 0
RandomInitialise(1802,9373);
#else
seed1 = sim_random() % 31329;
seed2 = sim_random() % 30082;
RandomInitialise(seed1,seed2);
#endif
}
uni = u[i97-1] - u[j97-1];
if (uni <= 0.0)
uni++;
u[i97-1] = uni;
i97--;
if (i97 == 0)
i97 = 97;
j97--;
if (j97 == 0)
j97 = 97;
c -= cd;
if (c < 0.0)
c += cm;
uni -= c;
if (uni < 0.0)
uni++;
return(uni);
}
/*
ALGORITHM 712, COLLECTED ALGORITHMS FROM ACM.
THIS WORK PUBLISHED IN TRANSACTIONS ON MATHEMATICAL SOFTWARE,
VOL. 18, NO. 4, DECEMBER, 1992, PP. 434-435.
The function returns a normally distributed pseudo-random number
with a given mean and standard devaiation. Calls are made to a
function subprogram which must return independent random
numbers uniform in the interval (0,1).
The algorithm uses the ratio of uniforms method of A.J. Kinderman
and J.F. Monahan augmented with quadratic bounding curves.
*/
double RandomGaussian(double mean,double stddev)
{
double q,z,v,x,y;
/*
Generate P = (u,v) uniform in rect. enclosing acceptance region
Make sure that any random numbers <= 0 are rejected, since
gaussian() requires uniforms > 0, but RandomUniform() delivers >= 0.
*/
do {
z = RandomUniform();
v = RandomUniform();
if (z <= 0.0 || v <= 0.0) {
z = 1.0;
v = 1.0;
}
v = 1.7156 * (v - 0.5);
/* Evaluate the quadratic form */
x = z - 0.449871;
y = fabs(v) + 0.386595;
q = x * x + y * (0.19600 * y - 0.25472 * x);
/* Accept P if inside inner ellipse */
if (q < 0.27597)
break;
/* Reject P if outside outer ellipse, or outside acceptance region */
} while ((q > 0.27846) || (v * v > -4.0 * log(z) * z * z));
/* Return ratio of P's coordinates as the normal deviate */
return (mean + stddev * v / z);
}
/*
Return random integer within a range, lower -> upper INCLUSIVE
*/
int RandomInt(int lower,int upper)
{
return((int)(RandomUniform() * (upper - lower + 1)) + lower);
}
/*
Return random float within a range, lower -> upper
*/
double RandomDouble(double lower,double upper)
{
return((upper - lower) * RandomUniform() + lower);
}
--- NEW FILE: randomlib.h ---
/*
This Random Number Generator is based on the algorithm in a FORTRAN
version published by George Marsaglia and Arif Zaman, Florida State
University; ref.: see original comments below.
At the fhw (Fachhochschule Wiesbaden, W.Germany), Dept. of Computer
Science, we have written sources in further languages (C, Modula-2
Turbo-Pascal(3.0, 5.0), Basic and Ada) to get exactly the same test
results compared with the original FORTRAN version.
April 1989
Karl-L. Noell <NOELL at DWIFH1.BITNET>
and Helmut Weber <WEBER at DWIFH1.BITNET>
This random number generator originally appeared in "Toward a Universal
Random Number Generator" by George Marsaglia and Arif Zaman.
Florida State University Report: FSU-SCRI-87-50 (1987)
It was later modified by F. James and published in "A Review of Pseudo-
random Number Generators"
THIS IS THE BEST KNOWN RANDOM NUMBER GENERATOR AVAILABLE.
(However, a newly discovered technique can yield
a period of 10^600. But that is still in the development stage.)
It passes ALL of the tests for random number generators and has a period
of 2^144, is completely portable (gives bit identical results on all
machines with at least 24-bit mantissas in the floating point
representation).
The algorithm is a combination of a Fibonacci sequence (with lags of 97
and 33, and operation "subtraction plus one, modulo one") and an
"arithmetic sequence" (using subtraction).
Use IJ = 1802 & KL = 9373 to test the random number generator. The
subroutine RANMAR should be used to generate 20000 random numbers.
Then display the next six random numbers generated multiplied by 4096*4096
If the random number generator is working properly, the random numbers
should be:
6533892.0 14220222.0 7275067.0
6172232.0 8354498.0 10633180.0
*/
#ifndef _RANDOMLIB_H_
#define _RANDOMLIB_H_
#ifdef __cplusplus
extern "C" {
#endif
void RandomInitialise(int,int);
double RandomUniform(void);
double RandomGaussian(double,double);
int RandomInt(int,int);
double RandomDouble(double,double);
#ifdef __cplusplus
}
#endif
#endif
Index: ActiveMessageC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/ActiveMessageC.nc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** ActiveMessageC.nc 12 Dec 2006 18:23:32 -0000 1.4
--- ActiveMessageC.nc 1 Apr 2007 00:29:34 -0000 1.5
***************
*** 48,52 ****
components TossimActiveMessageP as AM;
components TossimPacketModelC as Network;
! components UscGainInterferenceModelC as Model;
components ActiveMessageAddressC as Address;
components MainC;
--- 48,54 ----
components TossimActiveMessageP as AM;
components TossimPacketModelC as Network;
!
! components CpmModelC as Model;
!
components ActiveMessageAddressC as Address;
components MainC;
Index: TOSSIM.py
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/TOSSIM.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** TOSSIM.py 7 Nov 2006 19:31:21 -0000 1.3
--- TOSSIM.py 1 Apr 2007 00:29:34 -0000 1.4
***************
*** 1,36 ****
! # This file was created automatically by SWIG 1.3.29.
# Don't modify this file, modify the SWIG interface instead.
# This file is compatible with both classic and new-style classes.
-
import _TOSSIM
! import new
! new_instancemethod = new.instancemethod
! def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
! if (name == "thisown"): return self.this.own(value)
if (name == "this"):
! if type(value).__name__ == 'PySwigObject':
! self.__dict__[name] = value
return
method = class_type.__swig_setmethods__.get(name,None)
if method: return method(self,value)
! if (not static) or hasattr(self,name):
! self.__dict__[name] = value
! else:
! raise AttributeError("You cannot add attributes to %s" % self)
!
! def _swig_setattr(self,class_type,name,value):
! return _swig_setattr_nondynamic(self,class_type,name,value,0)
def _swig_getattr(self,class_type,name):
- if (name == "thisown"): return self.this.own()
method = class_type.__swig_getmethods__.get(name,None)
if method: return method(self)
raise AttributeError,name
- def _swig_repr(self):
- try: strthis = "proxy of " + self.this.__repr__()
- except: strthis = ""
- return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
-
import types
try:
--- 1,22 ----
! # This file was created automatically by SWIG.
# Don't modify this file, modify the SWIG interface instead.
# This file is compatible with both classic and new-style classes.
import _TOSSIM
! def _swig_setattr(self,class_type,name,value):
if (name == "this"):
! if isinstance(value, class_type):
! self.__dict__[name] = value.this
! if hasattr(value,"thisown"): self.__dict__["thisown"] = value.thisown
! del value.thisown
return
method = class_type.__swig_setmethods__.get(name,None)
if method: return method(self,value)
! self.__dict__[name] = value
def _swig_getattr(self,class_type,name):
method = class_type.__swig_getmethods__.get(name,None)
if method: return method(self)
raise AttributeError,name
import types
try:
***************
*** 40,44 ****
class _object : pass
_newclass = 0
- del types
--- 26,29 ----
***************
*** 48,84 ****
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, MAC, name)
! __repr__ = _swig_repr
! def __init__(self, *args):
! this = _TOSSIM.new_MAC(*args)
! try: self.this.append(this)
! except: self.this = this
! __swig_destroy__ = _TOSSIM.delete_MAC
! __del__ = lambda self : None;
! def initHigh(*args): return _TOSSIM.MAC_initHigh(*args)
! def initLow(*args): return _TOSSIM.MAC_initLow(*args)
! def high(*args): return _TOSSIM.MAC_high(*args)
! def low(*args): return _TOSSIM.MAC_low(*args)
! def symbolsPerSec(*args): return _TOSSIM.MAC_symbolsPerSec(*args)
! def bitsPerSymbol(*args): return _TOSSIM.MAC_bitsPerSymbol(*args)
! def preambleLength(*args): return _TOSSIM.MAC_preambleLength(*args)
! def exponentBase(*args): return _TOSSIM.MAC_exponentBase(*args)
! def maxIterations(*args): return _TOSSIM.MAC_maxIterations(*args)
! def minFreeSamples(*args): return _TOSSIM.MAC_minFreeSamples(*args)
! def rxtxDelay(*args): return _TOSSIM.MAC_rxtxDelay(*args)
! def ackTime(*args): return _TOSSIM.MAC_ackTime(*args)
! def setInitHigh(*args): return _TOSSIM.MAC_setInitHigh(*args)
! def setInitLow(*args): return _TOSSIM.MAC_setInitLow(*args)
! def setHigh(*args): return _TOSSIM.MAC_setHigh(*args)
! def setLow(*args): return _TOSSIM.MAC_setLow(*args)
! def setSymbolsPerSec(*args): return _TOSSIM.MAC_setSymbolsPerSec(*args)
! def setBitsBerSymbol(*args): return _TOSSIM.MAC_setBitsBerSymbol(*args)
! def setPreambleLength(*args): return _TOSSIM.MAC_setPreambleLength(*args)
! def setExponentBase(*args): return _TOSSIM.MAC_setExponentBase(*args)
! def setMaxIterations(*args): return _TOSSIM.MAC_setMaxIterations(*args)
! def setMinFreeSamples(*args): return _TOSSIM.MAC_setMinFreeSamples(*args)
! def setRxtxDelay(*args): return _TOSSIM.MAC_setRxtxDelay(*args)
! def setAckTime(*args): return _TOSSIM.MAC_setAckTime(*args)
! MAC_swigregister = _TOSSIM.MAC_swigregister
! MAC_swigregister(MAC)
class Radio(_object):
--- 33,76 ----
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, MAC, name)
! def __init__(self,*args):
! _swig_setattr(self, MAC, 'this', apply(_TOSSIM.new_MAC,args))
! _swig_setattr(self, MAC, 'thisown', 1)
! def __del__(self, destroy= _TOSSIM.delete_MAC):
! try:
! if self.thisown: destroy(self)
! except: pass
! def initHigh(*args): return apply(_TOSSIM.MAC_initHigh,args)
! def initLow(*args): return apply(_TOSSIM.MAC_initLow,args)
! def high(*args): return apply(_TOSSIM.MAC_high,args)
! def low(*args): return apply(_TOSSIM.MAC_low,args)
! def symbolsPerSec(*args): return apply(_TOSSIM.MAC_symbolsPerSec,args)
! def bitsPerSymbol(*args): return apply(_TOSSIM.MAC_bitsPerSymbol,args)
! def preambleLength(*args): return apply(_TOSSIM.MAC_preambleLength,args)
! def exponentBase(*args): return apply(_TOSSIM.MAC_exponentBase,args)
! def maxIterations(*args): return apply(_TOSSIM.MAC_maxIterations,args)
! def minFreeSamples(*args): return apply(_TOSSIM.MAC_minFreeSamples,args)
! def rxtxDelay(*args): return apply(_TOSSIM.MAC_rxtxDelay,args)
! def ackTime(*args): return apply(_TOSSIM.MAC_ackTime,args)
! def setInitHigh(*args): return apply(_TOSSIM.MAC_setInitHigh,args)
! def setInitLow(*args): return apply(_TOSSIM.MAC_setInitLow,args)
! def setHigh(*args): return apply(_TOSSIM.MAC_setHigh,args)
! def setLow(*args): return apply(_TOSSIM.MAC_setLow,args)
! def setSymbolsPerSec(*args): return apply(_TOSSIM.MAC_setSymbolsPerSec,args)
! def setBitsBerSymbol(*args): return apply(_TOSSIM.MAC_setBitsBerSymbol,args)
! def setPreambleLength(*args): return apply(_TOSSIM.MAC_setPreambleLength,args)
! def setExponentBase(*args): return apply(_TOSSIM.MAC_setExponentBase,args)
! def setMaxIterations(*args): return apply(_TOSSIM.MAC_setMaxIterations,args)
! def setMinFreeSamples(*args): return apply(_TOSSIM.MAC_setMinFreeSamples,args)
! def setRxtxDelay(*args): return apply(_TOSSIM.MAC_setRxtxDelay,args)
! def setAckTime(*args): return apply(_TOSSIM.MAC_setAckTime,args)
! def __repr__(self):
! return "<C MAC instance at %s>" % (self.this,)
!
! class MACPtr(MAC):
! def __init__(self,this):
! _swig_setattr(self, MAC, 'this', this)
! if not hasattr(self,"thisown"): _swig_setattr(self, MAC, 'thisown', 0)
! _swig_setattr(self, MAC,self.__class__,MAC)
! _TOSSIM.MAC_swigregister(MACPtr)
class Radio(_object):
***************
*** 87,105 ****
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, Radio, name)
! __repr__ = _swig_repr
! def __init__(self, *args):
! this = _TOSSIM.new_Radio(*args)
! try: self.this.append(this)
! except: self.this = this
! __swig_destroy__ = _TOSSIM.delete_Radio
! __del__ = lambda self : None;
! def add(*args): return _TOSSIM.Radio_add(*args)
! def gain(*args): return _TOSSIM.Radio_gain(*args)
! def connected(*args): return _TOSSIM.Radio_connected(*args)
! def remove(*args): return _TOSSIM.Radio_remove(*args)
! def setNoise(*args): return _TOSSIM.Radio_setNoise(*args)
! def setSensitivity(*args): return _TOSSIM.Radio_setSensitivity(*args)
! Radio_swigregister = _TOSSIM.Radio_swigregister
! Radio_swigregister(Radio)
class Packet(_object):
--- 79,104 ----
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, Radio, name)
! def __init__(self,*args):
! _swig_setattr(self, Radio, 'this', apply(_TOSSIM.new_Radio,args))
! _swig_setattr(self, Radio, 'thisown', 1)
! def __del__(self, destroy= _TOSSIM.delete_Radio):
! try:
! if self.thisown: destroy(self)
! except: pass
! def add(*args): return apply(_TOSSIM.Radio_add,args)
! def gain(*args): return apply(_TOSSIM.Radio_gain,args)
! def connected(*args): return apply(_TOSSIM.Radio_connected,args)
! def remove(*args): return apply(_TOSSIM.Radio_remove,args)
! def setNoise(*args): return apply(_TOSSIM.Radio_setNoise,args)
! def setSensitivity(*args): return apply(_TOSSIM.Radio_setSensitivity,args)
! def __repr__(self):
! return "<C Radio instance at %s>" % (self.this,)
!
! class RadioPtr(Radio):
! def __init__(self,this):
! _swig_setattr(self, Radio, 'this', this)
! if not hasattr(self,"thisown"): _swig_setattr(self, Radio, 'thisown', 0)
! _swig_setattr(self, Radio,self.__class__,Radio)
! _TOSSIM.Radio_swigregister(RadioPtr)
class Packet(_object):
***************
*** 108,132 ****
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, Packet, name)
! __repr__ = _swig_repr
! def __init__(self, *args):
! this = _TOSSIM.new_Packet(*args)
! try: self.this.append(this)
! except: self.this = this
! __swig_destroy__ = _TOSSIM.delete_Packet
! __del__ = lambda self : None;
! def setDestination(*args): return _TOSSIM.Packet_setDestination(*args)
! def destination(*args): return _TOSSIM.Packet_destination(*args)
! def setLength(*args): return _TOSSIM.Packet_setLength(*args)
! def length(*args): return _TOSSIM.Packet_length(*args)
! def setType(*args): return _TOSSIM.Packet_setType(*args)
! def type(*args): return _TOSSIM.Packet_type(*args)
! def data(*args): return _TOSSIM.Packet_data(*args)
! def setData(*args): return _TOSSIM.Packet_setData(*args)
! def maxLength(*args): return _TOSSIM.Packet_maxLength(*args)
! def setStrength(*args): return _TOSSIM.Packet_setStrength(*args)
! def deliver(*args): return _TOSSIM.Packet_deliver(*args)
! def deliverNow(*args): return _TOSSIM.Packet_deliverNow(*args)
! Packet_swigregister = _TOSSIM.Packet_swigregister
! Packet_swigregister(Packet)
class variable_string_t(_object):
--- 107,138 ----
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, Packet, name)
! def __init__(self,*args):
! _swig_setattr(self, Packet, 'this', apply(_TOSSIM.new_Packet,args))
! _swig_setattr(self, Packet, 'thisown', 1)
! def __del__(self, destroy= _TOSSIM.delete_Packet):
! try:
! if self.thisown: destroy(self)
! except: pass
! 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)
! def length(*args): return apply(_TOSSIM.Packet_length,args)
! def setType(*args): return apply(_TOSSIM.Packet_setType,args)
! def type(*args): return apply(_TOSSIM.Packet_type,args)
! def data(*args): return apply(_TOSSIM.Packet_data,args)
! def setData(*args): return apply(_TOSSIM.Packet_setData,args)
! def maxLength(*args): return apply(_TOSSIM.Packet_maxLength,args)
! def setStrength(*args): return apply(_TOSSIM.Packet_setStrength,args)
! def deliver(*args): return apply(_TOSSIM.Packet_deliver,args)
! def deliverNow(*args): return apply(_TOSSIM.Packet_deliverNow,args)
! def __repr__(self):
! return "<C Packet instance at %s>" % (self.this,)
!
! class PacketPtr(Packet):
! def __init__(self,this):
! _swig_setattr(self, Packet, 'this', this)
! if not hasattr(self,"thisown"): _swig_setattr(self, Packet, 'thisown', 0)
! _swig_setattr(self, Packet,self.__class__,Packet)
! _TOSSIM.Packet_swigregister(PacketPtr)
class variable_string_t(_object):
***************
*** 135,159 ****
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, variable_string_t, name)
- __repr__ = _swig_repr
__swig_setmethods__["type"] = _TOSSIM.variable_string_t_type_set
__swig_getmethods__["type"] = _TOSSIM.variable_string_t_type_get
! if _newclass:type = property(_TOSSIM.variable_string_t_type_get, _TOSSIM.variable_string_t_type_set)
__swig_setmethods__["ptr"] = _TOSSIM.variable_string_t_ptr_set
__swig_getmethods__["ptr"] = _TOSSIM.variable_string_t_ptr_get
! if _newclass:ptr = property(_TOSSIM.variable_string_t_ptr_get, _TOSSIM.variable_string_t_ptr_set)
__swig_setmethods__["len"] = _TOSSIM.variable_string_t_len_set
__swig_getmethods__["len"] = _TOSSIM.variable_string_t_len_get
! if _newclass:len = property(_TOSSIM.variable_string_t_len_get, _TOSSIM.variable_string_t_len_set)
__swig_setmethods__["isArray"] = _TOSSIM.variable_string_t_isArray_set
__swig_getmethods__["isArray"] = _TOSSIM.variable_string_t_isArray_get
! if _newclass:isArray = property(_TOSSIM.variable_string_t_isArray_get, _TOSSIM.variable_string_t_isArray_set)
! def __init__(self, *args):
! this = _TOSSIM.new_variable_string_t(*args)
! try: self.this.append(this)
! except: self.this = this
! __swig_destroy__ = _TOSSIM.delete_variable_string_t
! __del__ = lambda self : None;
! variable_string_t_swigregister = _TOSSIM.variable_string_t_swigregister
! variable_string_t_swigregister(variable_string_t)
class nesc_app_t(_object):
--- 141,172 ----
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, variable_string_t, name)
__swig_setmethods__["type"] = _TOSSIM.variable_string_t_type_set
__swig_getmethods__["type"] = _TOSSIM.variable_string_t_type_get
! if _newclass:type = property(_TOSSIM.variable_string_t_type_get,_TOSSIM.variable_string_t_type_set)
__swig_setmethods__["ptr"] = _TOSSIM.variable_string_t_ptr_set
__swig_getmethods__["ptr"] = _TOSSIM.variable_string_t_ptr_get
! if _newclass:ptr = property(_TOSSIM.variable_string_t_ptr_get,_TOSSIM.variable_string_t_ptr_set)
__swig_setmethods__["len"] = _TOSSIM.variable_string_t_len_set
__swig_getmethods__["len"] = _TOSSIM.variable_string_t_len_get
! if _newclass:len = property(_TOSSIM.variable_string_t_len_get,_TOSSIM.variable_string_t_len_set)
__swig_setmethods__["isArray"] = _TOSSIM.variable_string_t_isArray_set
__swig_getmethods__["isArray"] = _TOSSIM.variable_string_t_isArray_get
! if _newclass:isArray = property(_TOSSIM.variable_string_t_isArray_get,_TOSSIM.variable_string_t_isArray_set)
! def __init__(self,*args):
! _swig_setattr(self, variable_string_t, 'this', apply(_TOSSIM.new_variable_string_t,args))
! _swig_setattr(self, variable_string_t, 'thisown', 1)
! def __del__(self, destroy= _TOSSIM.delete_variable_string_t):
! try:
! if self.thisown: destroy(self)
! except: pass
! def __repr__(self):
! return "<C variable_string_t instance at %s>" % (self.this,)
!
! class variable_string_tPtr(variable_string_t):
! def __init__(self,this):
! _swig_setattr(self, variable_string_t, 'this', this)
! if not hasattr(self,"thisown"): _swig_setattr(self, variable_string_t, 'thisown', 0)
! _swig_setattr(self, variable_string_t,self.__class__,variable_string_t)
! _TOSSIM.variable_string_t_swigregister(variable_string_tPtr)
class nesc_app_t(_object):
***************
*** 162,186 ****
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, nesc_app_t, name)
- __repr__ = _swig_repr
__swig_setmethods__["numVariables"] = _TOSSIM.nesc_app_t_numVariables_set
__swig_getmethods__["numVariables"] = _TOSSIM.nesc_app_t_numVariables_get
! if _newclass:numVariables = property(_TOSSIM.nesc_app_t_numVariables_get, _TOSSIM.nesc_app_t_numVariables_set)
__swig_setmethods__["variableNames"] = _TOSSIM.nesc_app_t_variableNames_set
__swig_getmethods__["variableNames"] = _TOSSIM.nesc_app_t_variableNames_get
! if _newclass:variableNames = property(_TOSSIM.nesc_app_t_variableNames_get, _TOSSIM.nesc_app_t_variableNames_set)
__swig_setmethods__["variableTypes"] = _TOSSIM.nesc_app_t_variableTypes_set
__swig_getmethods__["variableTypes"] = _TOSSIM.nesc_app_t_variableTypes_get
! if _newclass:variableTypes = property(_TOSSIM.nesc_app_t_variableTypes_get, _TOSSIM.nesc_app_t_variableTypes_set)
__swig_setmethods__["variableArray"] = _TOSSIM.nesc_app_t_variableArray_set
__swig_getmethods__["variableArray"] = _TOSSIM.nesc_app_t_variableArray_get
! if _newclass:variableArray = property(_TOSSIM.nesc_app_t_variableArray_get, _TOSSIM.nesc_app_t_variableArray_set)
! def __init__(self, *args):
! this = _TOSSIM.new_nesc_app_t(*args)
! try: self.this.append(this)
! except: self.this = this
! __swig_destroy__ = _TOSSIM.delete_nesc_app_t
! __del__ = lambda self : None;
! nesc_app_t_swigregister = _TOSSIM.nesc_app_t_swigregister
! nesc_app_t_swigregister(nesc_app_t)
class Variable(_object):
--- 175,206 ----
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, nesc_app_t, name)
__swig_setmethods__["numVariables"] = _TOSSIM.nesc_app_t_numVariables_set
__swig_getmethods__["numVariables"] = _TOSSIM.nesc_app_t_numVariables_get
! if _newclass:numVariables = property(_TOSSIM.nesc_app_t_numVariables_get,_TOSSIM.nesc_app_t_numVariables_set)
__swig_setmethods__["variableNames"] = _TOSSIM.nesc_app_t_variableNames_set
__swig_getmethods__["variableNames"] = _TOSSIM.nesc_app_t_variableNames_get
! if _newclass:variableNames = property(_TOSSIM.nesc_app_t_variableNames_get,_TOSSIM.nesc_app_t_variableNames_set)
__swig_setmethods__["variableTypes"] = _TOSSIM.nesc_app_t_variableTypes_set
__swig_getmethods__["variableTypes"] = _TOSSIM.nesc_app_t_variableTypes_get
! if _newclass:variableTypes = property(_TOSSIM.nesc_app_t_variableTypes_get,_TOSSIM.nesc_app_t_variableTypes_set)
__swig_setmethods__["variableArray"] = _TOSSIM.nesc_app_t_variableArray_set
__swig_getmethods__["variableArray"] = _TOSSIM.nesc_app_t_variableArray_get
! if _newclass:variableArray = property(_TOSSIM.nesc_app_t_variableArray_get,_TOSSIM.nesc_app_t_variableArray_set)
! def __init__(self,*args):
! _swig_setattr(self, nesc_app_t, 'this', apply(_TOSSIM.new_nesc_app_t,args))
! _swig_setattr(self, nesc_app_t, 'thisown', 1)
! def __del__(self, destroy= _TOSSIM.delete_nesc_app_t):
! try:
! if self.thisown: destroy(self)
! except: pass
! def __repr__(self):
! return "<C nesc_app_t instance at %s>" % (self.this,)
!
! class nesc_app_tPtr(nesc_app_t):
! def __init__(self,this):
! _swig_setattr(self, nesc_app_t, 'this', this)
! if not hasattr(self,"thisown"): _swig_setattr(self, nesc_app_t, 'thisown', 0)
! _swig_setattr(self, nesc_app_t,self.__class__,nesc_app_t)
! _TOSSIM.nesc_app_t_swigregister(nesc_app_tPtr)
class Variable(_object):
***************
*** 189,202 ****
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, Variable, name)
! __repr__ = _swig_repr
! def __init__(self, *args):
! this = _TOSSIM.new_Variable(*args)
! try: self.this.append(this)
! except: self.this = this
! __swig_destroy__ = _TOSSIM.delete_Variable
! __del__ = lambda self : None;
! def getData(*args): return _TOSSIM.Variable_getData(*args)
! Variable_swigregister = _TOSSIM.Variable_swigregister
! Variable_swigregister(Variable)
class Mote(_object):
--- 209,229 ----
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, Variable, name)
! def __init__(self,*args):
! _swig_setattr(self, Variable, 'this', apply(_TOSSIM.new_Variable,args))
! _swig_setattr(self, Variable, 'thisown', 1)
! def __del__(self, destroy= _TOSSIM.delete_Variable):
! try:
! if self.thisown: destroy(self)
! except: pass
! def getData(*args): return apply(_TOSSIM.Variable_getData,args)
! def __repr__(self):
! return "<C Variable instance at %s>" % (self.this,)
!
! class VariablePtr(Variable):
! def __init__(self,this):
! _swig_setattr(self, Variable, 'this', this)
! if not hasattr(self,"thisown"): _swig_setattr(self, Variable, 'thisown', 0)
! _swig_setattr(self, Variable,self.__class__,Variable)
! _TOSSIM.Variable_swigregister(VariablePtr)
class Mote(_object):
***************
*** 205,226 ****
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, Mote, name)
! __repr__ = _swig_repr
! def __init__(self, *args):
! this = _TOSSIM.new_Mote(*args)
! try: self.this.append(this)
! except: self.this = this
! __swig_destroy__ = _TOSSIM.delete_Mote
! __del__ = lambda self : None;
! def id(*args): return _TOSSIM.Mote_id(*args)
! def euid(*args): return _TOSSIM.Mote_euid(*args)
! def setEuid(*args): return _TOSSIM.Mote_setEuid(*args)
! def bootTime(*args): return _TOSSIM.Mote_bootTime(*args)
! def bootAtTime(*args): return _TOSSIM.Mote_bootAtTime(*args)
! def isOn(*args): return _TOSSIM.Mote_isOn(*args)
! def turnOff(*args): return _TOSSIM.Mote_turnOff(*args)
! def turnOn(*args): return _TOSSIM.Mote_turnOn(*args)
! def getVariable(*args): return _TOSSIM.Mote_getVariable(*args)
! Mote_swigregister = _TOSSIM.Mote_swigregister
! Mote_swigregister(Mote)
class Tossim(_object):
--- 232,263 ----
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, Mote, name)
! def __init__(self,*args):
! _swig_setattr(self, Mote, 'this', apply(_TOSSIM.new_Mote,args))
! _swig_setattr(self, Mote, 'thisown', 1)
! def __del__(self, destroy= _TOSSIM.delete_Mote):
! try:
! if self.thisown: destroy(self)
! except: pass
! def id(*args): return apply(_TOSSIM.Mote_id,args)
! def euid(*args): return apply(_TOSSIM.Mote_euid,args)
! def setEuid(*args): return apply(_TOSSIM.Mote_setEuid,args)
! def bootTime(*args): return apply(_TOSSIM.Mote_bootTime,args)
! def bootAtTime(*args): return apply(_TOSSIM.Mote_bootAtTime,args)
! def isOn(*args): return apply(_TOSSIM.Mote_isOn,args)
! def turnOff(*args): return apply(_TOSSIM.Mote_turnOff,args)
! def turnOn(*args): return apply(_TOSSIM.Mote_turnOn,args)
! def getVariable(*args): return apply(_TOSSIM.Mote_getVariable,args)
! def addNoiseTraceReading(*args): return apply(_TOSSIM.Mote_addNoiseTraceReading,args)
! def createNoiseModel(*args): return apply(_TOSSIM.Mote_createNoiseModel,args)
! def generateNoise(*args): return apply(_TOSSIM.Mote_generateNoise,args)
! def __repr__(self):
! return "<C Mote instance at %s>" % (self.this,)
!
! class MotePtr(Mote):
! def __init__(self,this):
! _swig_setattr(self, Mote, 'this', this)
! if not hasattr(self,"thisown"): _swig_setattr(self, Mote, 'thisown', 0)
! _swig_setattr(self, Mote,self.__class__,Mote)
! _TOSSIM.Mote_swigregister(MotePtr)
class Tossim(_object):
***************
*** 229,257 ****
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, Tossim, name)
! __repr__ = _swig_repr
! def __init__(self, *args):
! this = _TOSSIM.new_Tossim(*args)
! try: self.this.append(this)
! except: self.this = this
! __swig_destroy__ = _TOSSIM.delete_Tossim
! __del__ = lambda self : None;
! def init(*args): return _TOSSIM.Tossim_init(*args)
! def time(*args): return _TOSSIM.Tossim_time(*args)
! def ticksPerSecond(*args): return _TOSSIM.Tossim_ticksPerSecond(*args)
! def setTime(*args): return _TOSSIM.Tossim_setTime(*args)
! def timeStr(*args): return _TOSSIM.Tossim_timeStr(*args)
! def currentNode(*args): return _TOSSIM.Tossim_currentNode(*args)
! def getNode(*args): return _TOSSIM.Tossim_getNode(*args)
! def setCurrentNode(*args): return _TOSSIM.Tossim_setCurrentNode(*args)
! def addChannel(*args): return _TOSSIM.Tossim_addChannel(*args)
! def removeChannel(*args): return _TOSSIM.Tossim_removeChannel(*args)
! def randomSeed(*args): return _TOSSIM.Tossim_randomSeed(*args)
! def runNextEvent(*args): return _TOSSIM.Tossim_runNextEvent(*args)
! def mac(*args): return _TOSSIM.Tossim_mac(*args)
! def radio(*args): return _TOSSIM.Tossim_radio(*args)
! def newPacket(*args): return _TOSSIM.Tossim_newPacket(*args)
! Tossim_swigregister = _TOSSIM.Tossim_swigregister
! Tossim_swigregister(Tossim)
--- 266,300 ----
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, Tossim, name)
! def __init__(self,*args):
! _swig_setattr(self, Tossim, 'this', apply(_TOSSIM.new_Tossim,args))
! _swig_setattr(self, Tossim, 'thisown', 1)
! def __del__(self, destroy= _TOSSIM.delete_Tossim):
! try:
! if self.thisown: destroy(self)
! except: pass
! def init(*args): return apply(_TOSSIM.Tossim_init,args)
! def time(*args): return apply(_TOSSIM.Tossim_time,args)
! def ticksPerSecond(*args): return apply(_TOSSIM.Tossim_ticksPerSecond,args)
! def setTime(*args): return apply(_TOSSIM.Tossim_setTime,args)
! def timeStr(*args): return apply(_TOSSIM.Tossim_timeStr,args)
! def currentNode(*args): return apply(_TOSSIM.Tossim_currentNode,args)
! def getNode(*args): return apply(_TOSSIM.Tossim_getNode,args)
! def setCurrentNode(*args): return apply(_TOSSIM.Tossim_setCurrentNode,args)
! def addChannel(*args): return apply(_TOSSIM.Tossim_addChannel,args)
! def removeChannel(*args): return apply(_TOSSIM.Tossim_removeChannel,args)
! def randomSeed(*args): return apply(_TOSSIM.Tossim_randomSeed,args)
! def runNextEvent(*args): return apply(_TOSSIM.Tossim_runNextEvent,args)
! def mac(*args): return apply(_TOSSIM.Tossim_mac,args)
! def radio(*args): return apply(_TOSSIM.Tossim_radio,args)
! def newPacket(*args): return apply(_TOSSIM.Tossim_newPacket,args)
! def __repr__(self):
! return "<C Tossim instance at %s>" % (self.this,)
+ class TossimPtr(Tossim):
+ def __init__(self,this):
+ _swig_setattr(self, Tossim, 'this', this)
+ if not hasattr(self,"thisown"): _swig_setattr(self, Tossim, 'thisown', 0)
+ _swig_setattr(self, Tossim,self.__class__,Tossim)
+ _TOSSIM.Tossim_swigregister(TossimPtr)
Index: hashtable.c
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/hashtable.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** hashtable.c 12 Jul 2006 17:02:34 -0000 1.2
--- hashtable.c 1 Apr 2007 00:29:34 -0000 1.3
***************
*** 152,155 ****
--- 152,158 ----
e->h = hash(h,k);
tindex = indexFor(h->tablelength,e->h);
+ if (v == (void*)0x477fed00) {
+ printf("CORRUPT\n");
+ }
e->k = k;
e->v = v;
***************
*** 168,176 ****
tindex = indexFor(h->tablelength,hashvalue);
e = h->table[tindex];
while (NULL != e)
{
/* Check hash value to short circuit heavier comparison */
! if ((hashvalue == e->h) && (h->eqfn(k, e->k))) return e->v;
! e = e->next;
}
return NULL;
--- 171,187 ----
tindex = indexFor(h->tablelength,hashvalue);
e = h->table[tindex];
+ if (hashvalue == 1741511095) {
+ int i = 5;
+ }
while (NULL != e)
{
/* Check hash value to short circuit heavier comparison */
! if ((hashvalue == e->h) && (h->eqfn(k, e->k))) {
! if ((int)e->v == 0x477fed00) {
! printf("ALARM\n");
! }
! return e->v;
! }
! e = e->next;
}
return NULL;
Index: sim_gain.c
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/sim_gain.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** sim_gain.c 12 Dec 2006 18:23:35 -0000 1.3
--- sim_gain.c 1 Apr 2007 00:29:34 -0000 1.4
***************
*** 8,12 ****
gain_entry_t* connectivity[TOSSIM_MAX_NODES + 1];
! sim_gain_noise_t noise[TOSSIM_MAX_NODES + 1];
double sensitivity = 4.0;
--- 8,12 ----
gain_entry_t* connectivity[TOSSIM_MAX_NODES + 1];
! sim_gain_noise_t localNoise[TOSSIM_MAX_NODES + 1];
double sensitivity = 4.0;
***************
*** 122,127 ****
node = TOSSIM_MAX_NODES;
}
! noise[node].mean = mean;
! noise[node].range = range;
}
--- 122,127 ----
node = TOSSIM_MAX_NODES;
}
! localNoise[node].mean = mean;
! localNoise[node].range = range;
}
***************
*** 130,134 ****
node = TOSSIM_MAX_NODES;
}
! return noise[node].mean;
}
--- 130,134 ----
node = TOSSIM_MAX_NODES;
}
! return localNoise[node].mean;
}
***************
*** 137,141 ****
node = TOSSIM_MAX_NODES;
}
! return noise[node].range;
}
--- 137,141 ----
node = TOSSIM_MAX_NODES;
}
! return localNoise[node].range;
}
***************
*** 147,155 ****
node = TOSSIM_MAX_NODES;
}
! val = noise[node].mean;
adjust = (sim_random() % 2000000);
adjust /= 1000000.0;
adjust -= 1.0;
! adjust *= noise[node].range;
return val + adjust;
}
--- 147,155 ----
node = TOSSIM_MAX_NODES;
}
! val = localNoise[node].mean;
adjust = (sim_random() % 2000000);
adjust /= 1000000.0;
adjust -= 1.0;
! adjust *= localNoise[node].range;
return val + adjust;
}
Index: sim_log.c
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/sim_log.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** sim_log.c 12 Dec 2006 18:23:35 -0000 1.4
--- sim_log.c 1 Apr 2007 00:29:34 -0000 1.5
***************
*** 299,306 ****
char* str = (char*)key;
unsigned int hashVal = 0;
! int c;
! while ((c = *str++))
! hashVal = c + (hashVal << 6) + (hashVal << 16) - hashVal;
return hashVal;
--- 299,306 ----
char* str = (char*)key;
unsigned int hashVal = 0;
! int hashChar;
! while ((hashChar = *str++))
! hashVal = hashChar + (hashVal << 6) + (hashVal << 16) - hashVal;
return hashVal;
Index: sim_mac.c
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/sim_mac.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** sim_mac.c 12 Jul 2006 17:02:36 -0000 1.2
--- sim_mac.c 1 Apr 2007 00:29:34 -0000 1.3
***************
*** 33,34 ****
--- 33,39 ----
#include <sim_csma.c>
#include <sim_gain.c>
+
+ //Added by HyungJune Lee
+ #include <randomlib.c>
+ #include <sim_noise.c>
+
Index: sim_noise.c
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/sim_noise.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** sim_noise.c 7 Mar 2007 01:07:10 -0000 1.2
--- sim_noise.c 1 Apr 2007 00:29:34 -0000 1.3
***************
*** 1,379 ****
/*
! * Copyright (c) 2006 Stanford University.
! * All rights reserved.
! *
! * Redistribution and use in source and binary forms, with or without
! * modification, are permitted provided that the following conditions
! * are met:
! * - Redistributions of source code must retain the above copyright
! * notice, this list of conditions and the following disclaimer.
! * - Redistributions in binary form must reproduce the above copyright
! * notice, this list of conditions and the following disclaimer in the
! * documentation and/or other materials provided with the
! * distribution.
! * - Neither the name of the Stanford University nor the names of
! * its contributors may be used to endorse or promote products derived
! * from this software without specific prior written permission.
*
! * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
! * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
! * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
! * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD
! * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
! * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
! * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
! * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
! * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
! * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
! * OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
! * The C functions for accessing TOSSIM's noise simulation data
! * structures.
*
! * @author Philip Levis
! * @date Mar 2 2007
*/
-
- // $Id$
-
-
- #include <tos.h>
-
- #include <sim_noise.h>
- #include <hashtable.h>
-
- #ifdef TESTING
- #include <hashtable.c>
#include <stdio.h>
#include <stdlib.h>
! #define TOSSIM_MAX_NODE 20
! sim_time_t sim_mote_start_time(int mote) {
! return 37;
! }
! sim_time_t sim_ticks_per_sec() {
! return 10000000;
! }
! #endif
! typedef struct noise_distribution {
! int minValue;
! int numBuckets;
! int discretization;
! int sum;
! int* counts;
! } noise_distribution_t;
! typedef struct noise_model {
! uint32_t historyLength; // The history "k" of the model
! uint32_t sampleRateHz; // The rate at which samples change
! hashtable_t* table; // A pointer to the distribution hashtable
! noise_distribution_t* common; // Most common distribution
! double* firstReadings; // An array of the first k values of the trace
! double* lastReadings; // An array of the last k values observed
! uint32_t lastReading; // When was the last value observed
! uint8_t discretization; // The discretization unit for readings
! sim_time_t increment; // The sim_time between samples (derived from sample rate)
! uint16_t bins; // The number of noise value bins (range / discretization)
! double minNoise; // The minimum noise value
! bool dirty; // Has data been added to the model so it needs to be recomputed?
! } noise_model_t;
! noise_model_t models[TOSSIM_MAX_NODE];
! void clear_data(uint32_t mote);
! void add_data(uint32_t mote, double value);
! void generate_model(int mote);
! static unsigned int sim_noise_hash(void* key);
! static int sim_noise_equal(void* key1, void* key2);
! noise_distribution_t* create_noise_distribution(int mote);
! void add_val_to_distribution(noise_distribution_t* dist, int value);
! int make_discrete(double value, uint8_t discretization) {
! int val = (int)value;
! val /= discretization;
! val *= discretization;
! }
- void create_model(uint32_t mote, uint32_t sampleRate, uint32_t historyLength, uint8_t discretization, uint16_t bins, double minNoise) {
- int i;
- if (mote < TOSSIM_MAX_NODES) {
- models[mote].historyLength = historyLength;
- models[mote].sampleRateHz = sampleRate;
- models[mote].table = create_hashtable(10240, sim_noise_hash, sim_noise_equal);
- models[mote].lastReadings = (double*)(malloc(sizeof(double) * historyLength));
- models[mote].discretization = discretization;
- models[mote].lastReading = historyLength - 1;
- for (i = 0; i < historyLength; i++) {
- models[mote].lastReadings[i] = 0.0;
- }
- models[mote].dirty = FALSE;
- models[mote].bins = bins;
- models[mote].minNoise = minNoise;
- models[mote].increment = sim_ticks_per_sec() / models[mote].sampleRateHz;
- clear_data(mote);
}
}
! void clear_model(uint32_t mote) {
! clear_data(mote);
! if (models[mote].table != NULL) {
! hashtable_destroy(models[mote].table, 1);
! models[mote].table = NULL;
}
! if (models[mote].lastReadings != NULL) {
! free(models[mote].lastReadings);
! models[mote].lastReadings = NULL;
}
}
! void add_reading(int mote, double value) {
! add_data(mote, value);
! models[mote].dirty = 1;
}
! char* hashString = NULL;
! int hashStringLength = 0;
! #define SAMPLE_STR_LEN 10
! char* generateHashString(double* readings, int len, int discretization) {
! char* ptr;
int i;
! if (hashStringLength < len * SAMPLE_STR_LEN) {
! int newLen = (len * SAMPLE_STR_LEN);
! free(hashString);
! hashString = (char*)malloc(sizeof(char) * newLen + 1);
! hashStringLength = newLen;
! }
! ptr = hashString;
! for (i = 0; i < len; i++) {
! int val = make_discrete(readings[i], discretization);
! ptr += snprintf(ptr, SAMPLE_STR_LEN, "%i ", val);
}
! return hashString;
}
- static int sim_seed = 2342;
! int sim_random() {
! uint32_t mlcg,p,q;
! uint64_t tmpseed;
! tmpseed = (uint64_t)33614U * (uint64_t)sim_seed;
! q = tmpseed; /* low */
! q = q >> 1;
! p = tmpseed >> 32 ; /* hi */
! mlcg = p + q;
! if (mlcg & 0x80000000) {
! mlcg = mlcg & 0x7FFFFFFF;
! mlcg++;
! }
! sim_seed = mlcg;
! return mlcg;
}
! double sampleDistribution(noise_distribution_t* dist) {
! double rval = 0.0;
! if (dist->sum == 0) {
! return rval;
! }
! else {
! int which = sim_random() % dist->sum;
! int total = 0;
! int i;
! printf("%i of ", which);
! for (i = 0; i < dist->numBuckets; i++) {
! printf("[%i] ", dist->counts[i]);
}
! printf("\n");
! for (i = 0; i < dist->numBuckets; i++) {
! total += dist->counts[i];
! if (total > which) {
! printf("Sampling %i\n", i);
! rval = (i * dist->discretization) + dist->minValue;
! break;
! }
}
}
- // Should never reach this
- return rval;
- }
! void appendReading(int mote, double reading) {
! int size = ((models[mote].historyLength - 1) * sizeof(double));
! memcpy(models[mote].lastReadings, models[mote].lastReadings + 1, size);
! models[mote].lastReadings[models[mote].historyLength - 1] = reading;
! models[mote].lastReading++;
! }
! void generateReading(int mote) {
! char* str = generateHashString(models[mote].lastReadings, models[mote].historyLength, models[mote].discretization) ;
! printf("%s : ", str);
! noise_distribution_t* noise = (noise_distribution_t*)hashtable_search(models[mote].table, hashString);
! if (noise == NULL) {
! printf("Using default distribution: ");
! noise = models[mote].common;
! }
! double reading = sampleDistribution(noise);
! //printf("reading: %f\n", reading);
! appendReading(mote, reading);
! }
! void generateReadings(int mote, uint64_t count) {
! uint64_t i;
! for (i = 0; i < count; i++) {
! generateReading(mote);
! }
}
! double getSample(int mote, sim_time_t time) {
! int64_t readingNo;
! int64_t readingCount;
! sim_time_t timePassed = time - sim_mote_start_time(mote);
! noise_model_t* model = &models[mote];
! if (timePassed < 0) {
! return (double)make_discrete(model->firstReadings[0], model->discretization);
! }
! if (model->dirty) {
! generate_model(mote);
! }
! readingNo = timePassed / (uint64_t)model->increment;
! if (readingNo < model->historyLength) {
! return make_discrete(model->firstReadings[readingNo], model->discretization);
}
! readingCount = readingNo - model->lastReading;
! generateReadings(mote, readingCount);
! return make_discrete(model->lastReadings[0], model->discretization);
! }
!
!
!
! typedef struct noise_data {
! uint32_t size;
! uint32_t maxSize;
! double* readings;
! } noise_data_t;
! noise_data_t data[TOSSIM_MAX_NODE];
! void init_data(uint32_t mote) {
! if (mote < TOSSIM_MAX_NODE) {
! data[mote].size = 0;
! data[mote].maxSize = 1024;
! data[mote].readings = (double*)(malloc(sizeof(double) * 1024));
! }
}
!
! void clear_data(uint32_t mote) {
! if (mote < TOSSIM_MAX_NODE) {
! if (data[mote].readings != NULL) {
! free(data[mote].readings);
! data[mote].readings = NULL;
}
! init_data(mote);
! }
}
! void add_data(uint32_t mote, double value) {
! if (mote < TOSSIM_MAX_NODE) {
! if (data[mote].size == data[mote].maxSize) {
! double* ndata = (double*)malloc(sizeof(double) * 2 * data[mote].maxSize);
! memcpy(ndata, data[mote].readings, data[mote].size * sizeof(double));
! free(data[mote].readings);
! data[mote].readings = ndata;
! data[mote].maxSize *= 2;
}
! data[mote].readings[data[mote].size] = value;
! data[mote].size++;
}
}
! static unsigned int sim_noise_hash(void* key) {
! char* str = (char*)key;
! unsigned int hashVal = 0;
! int c;
! while ((c = *str++))
! hashVal = c + (hashVal << 6) + (hashVal << 16) - hashVal;
! return hashVal;
}
! static int sim_noise_equal(void* key1, void* key2) {
! return (strcmp((char*)key1, (char*)key2) == 0);
! }
! void generate_model(int mote) {
! uint64_t i;
! noise_model_t* noiseModel = &models[mote];
! noise_data_t* noiseData = &data[mote];
! noise_distribution_t* maxDist = NULL;
! // Not enough data to generate a model
! if (noiseData->size <= noiseModel->historyLength) {
! return;
! }
! free(noiseModel->firstReadings);
! noiseModel->firstReadings = (double*) malloc(sizeof(double) * noiseModel->historyLength);
! for (i = 0; i < noiseModel->historyLength; i++) {
! noiseModel->firstReadings[i] = noiseModel->lastReadings[i] = noiseData->readings[i];
}
! for (;i < data[mote].size; i++) {
! double* dataStart = noiseData->readings + (i - noiseModel->historyLength);
! int dataLen = noiseModel->historyLength;
! int discretize = noiseModel->discretization;
! char* hashStr = generateHashString(dataStart, dataLen, discretize);
! int value = make_discrete(noiseData->readings[i], discretize);
! noise_distribution_t* dist = (noise_distribution_t*)hashtable_search(noiseModel->table, hashStr);
! if (dist == NULL) {
! dist = create_noise_distribution(mote);
! hashtable_insert(noiseModel->table, hashStr, dist);
! }
! add_val_to_distribution(dist, value);
! if (maxDist == NULL || dist->sum > maxDist->sum) {
! maxDist = dist;
}
! //printf ("%llu: %s -> %i\n", i, hashStr, value);
}
! noiseModel->common = maxDist;
! noiseModel->dirty = 0;
}
! int main() {
int i;
! char* hashStr;
! create_model(0, 1024, 10, 1, 10, 0);
! for (i = 0; i < 2000000; i++) {
! add_reading(0, (drand48() * 8.0));
}
! generate_model(0);
! for (i = 0; i < 10000; i++) {
! double sample = getSample(0, sim_mote_start_time(0) + i * sim_ticks_per_sec() / 1024);
! printf("%i: %f\n", i, sample);
}
}
- noise_distribution_t* create_noise_distribution(int mote) {
- noise_model_t* model = &models[mote];
- noise_distribution_t* dist = (noise_distribution_t*)malloc(sizeof(noise_distribution_t));
- dist->minValue = (int)model->minNoise;
- dist->numBuckets = model->bins;
- dist->sum = 0;
- dist->discretization = model->discretization;
- dist->counts = (int*)malloc(sizeof(int) * dist->numBuckets);
- memset(dist->counts, 0, sizeof(int) * dist->numBuckets);
- return dist;
- }
- void add_val_to_distribution(noise_distribution_t* dist, int value) {
- int index = value - dist->minValue;
- index /= dist->discretization;
- dist->counts[index]++;
- dist->sum++;
- //printf("Adding %i (%i:%i)\n", value, dist->sum, dist->counts[index]);
- }
--- 1,395 ----
/*
! * "Copyright (c) 2006 Stanford University. All rights reserved.
*
! * Permission to use, copy, modify, and distribute this software and
! * its documentation for any purpose, without fee, and without written
! * agreement is hereby granted, provided that the above copyright
! * notice, the following two paragraphs and the author appear in all
! * copies of this software.
! *
! * IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE TO ANY PARTY FOR
! * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
! * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
! * IF STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
! * DAMAGE.
! *
! * STANFORD UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
! * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
! * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
! * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND STANFORD UNIVERSITY
! * HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
! * ENHANCEMENTS, OR MODIFICATIONS."
*/
/**
! * Implementation of all of the Hash-Based Learning primitives and utility
! * functions.
*
! * @author Hyungjune Lee
! * @date Oct 13 2006
*/
#include <stdio.h>
#include <stdlib.h>
! #include <string.h>
! #include <math.h>
! #include <sys/time.h>
! #include <time.h>
! #include "randomlib.h"
! #include "hashtable.h"
! #include "sim_noise.h"
! uint32_t FreqKeyNum = 0;
! sim_noise_node_t noiseData[TOSSIM_MAX_NODES];
! static unsigned int sim_noise_hash(void *key);
! static int sim_noise_eq(void *key1, void *key2);
! void makeNoiseModel(uint16_t node_id);
! void makePmfDistr(uint16_t node_id);
! uint8_t search_bin_num(char noise);
! void sim_noise_init()__attribute__ ((C, spontaneous))
! {
! int j;
!
! //printf("Starting\n");
!
! for (j=0; j< TOSSIM_MAX_NODES; j++) {
! noiseData[j].noiseTable = create_hashtable(NOISE_HASHTABLE_SIZE, sim_noise_hash, sim_noise_eq);
! noiseData[j].noiseGenTime = 0;
! noiseData[j].noiseTrace = (char*)(malloc(sizeof(char) * NOISE_MIN_TRACE));
! noiseData[j].noiseTraceLen = NOISE_MIN_TRACE;
! noiseData[j].noiseTraceIndex = 0;
}
+ //printf("Done with sim_noise_init()\n");
}
! void sim_noise_create_model(uint16_t node_id)__attribute__ ((C, spontaneous)) {
! makeNoiseModel(node_id);
! makePmfDistr(node_id);
! }
!
! char sim_real_noise(uint16_t node_id, uint32_t cur_t) {
! if (cur_t > noiseData[node_id].noiseTraceLen) {
! dbg("Noise", "Asked for noise element %u when there are only %u.\n", cur_t, noiseData[node_id].noiseTraceIndex);
! return 0;
}
! return noiseData[node_id].noiseTrace[cur_t];
! }
!
! void sim_noise_trace_add(uint16_t node_id, char noiseVal)__attribute__ ((C, spontaneous)) {
! // Need to double size of trace arra
! if (noiseData[node_id].noiseTraceIndex ==
! noiseData[node_id].noiseTraceLen) {
! char* data = (char*)(malloc(sizeof(char) * noiseData[node_id].noiseTraceLen * 2));
! memcpy(data, noiseData[node_id].noiseTrace, noiseData[node_id].noiseTraceLen);
! free(noiseData[node_id].noiseTrace);
! noiseData[node_id].noiseTraceLen *= 2;
! noiseData[node_id].noiseTrace = data;
}
+ noiseData[node_id].noiseTrace[noiseData[node_id].noiseTraceIndex] = noiseVal;
+ noiseData[node_id].noiseTraceIndex++;
}
!
! uint8_t search_bin_num(char noise)__attribute__ ((C, spontaneous))
! {
! uint8_t bin;
! bin = (noise-NOISE_MIN)/NOISE_QUANTIZE_INTERVAL + 1;
! return bin;
}
! char search_noise_from_bin_num(int i)__attribute__ ((C, spontaneous))
! {
! char noise;
! noise = NOISE_MIN + (i-1)*NOISE_QUANTIZE_INTERVAL;
! return noise;
! }
! static unsigned int sim_noise_hash(void *key) {
! char *pt = (char *)key;
! unsigned int hashVal = 0;
int i;
! for (i=0; i< NOISE_HISTORY; i++) {
! hashVal = pt[i] + (hashVal << 6) + (hashVal << 16) - hashVal;
}
! return hashVal;
}
! static int sim_noise_eq(void *key1, void *key2) {
! return (memcmp((void *)key1, (void *)key2, NOISE_HISTORY) == 0);
}
! void sim_noise_add(uint16_t node_id, char noise)__attribute__ ((C, spontaneous))
! {
! int i;
! struct hashtable *pnoiseTable = noiseData[node_id].noiseTable;
! char *key = noiseData[node_id].key;
! sim_noise_hash_t *noise_hash;
! noise_hash = (sim_noise_hash_t *)hashtable_search(pnoiseTable, key);
! dbg("Insert,HashZeroDebug", "Adding noise value %hhi\n", noise);
! if (noise_hash == NULL) {
! noise_hash = (sim_noise_hash_t *)malloc(sizeof(sim_noise_hash_t));
! memcpy((void *)(noise_hash->key), (void *)key, NOISE_HISTORY);
!
! noise_hash->numElements = 0;
! noise_hash->size = NOISE_DEFAULT_ELEMENT_SIZE;
! noise_hash->elements = (char *)malloc(sizeof(char)*noise_hash->size);
! memset((void *)noise_hash->elements, 0, sizeof(char)*noise_hash->size);
!
! noise_hash->flag = 0;
! for(i=0; i<NOISE_BIN_SIZE; i++) {
! noise_hash->dist[i] = 0;
}
! hashtable_insert(pnoiseTable, key, noise_hash);
! dbg("Insert", "Inserting %p into table %p with key ", noise_hash, pnoiseTable);
! {
! int ctr;
! for(ctr = 0; ctr < NOISE_HISTORY; ctr++)
! dbg_clear("Insert", "%0.3hhi ", key[ctr]);
}
+ dbg_clear("Insert", "\n");
}
! if (noise_hash->numElements == noise_hash->size)
! {
! char *newElements;
! int newSize = (noise_hash->size)*2;
! newElements = (char *)malloc(sizeof(char)*newSize);
! memcpy(newElements, noise_hash->elements, noise_hash->size);
! free(noise_hash->elements);
! noise_hash->elements = newElements;
! noise_hash->size = newSize;
! }
! noise_hash->elements[noise_hash->numElements] = noise;
! noise_hash->numElements++;
}
! void sim_noise_dist(uint16_t node_id)__attribute__ ((C, spontaneous))
! {
! int i;
! uint8_t bin;
! float cmf = 0;
! struct hashtable *pnoiseTable = noiseData[node_id].noiseTable;
! char *key = noiseData[node_id].key;
! char *freqKey = noiseData[node_id].freqKey;
! sim_noise_hash_t *noise_hash;
! noise_hash = (sim_noise_hash_t *)hashtable_search(pnoiseTable, key);
! if (noise_hash->flag == 1)
! return;
!
! for (i=0; i < NOISE_BIN_SIZE; i++) {
! noise_hash->dist[i] = 0.0;
}
! for (i=0; i< noise_hash->numElements; i++)
! {
! float val;
! bin = search_bin_num(noise_hash->elements[i]) - 1;
! val = noise_hash->dist[bin];
! val += (float)1.0;
! noise_hash->dist[bin] = val;
! }
! for (i=0; i < NOISE_BIN_SIZE ; i++)
! {
! noise_hash->dist[i] = (noise_hash->dist[i])/(noise_hash->numElements);
! cmf += noise_hash->dist[i];
! noise_hash->dist[i] = cmf;
! }
! noise_hash->flag = 1;
! //Find the most frequent key and store it in noiseData[node_id].freqKey[].
! if (noise_hash->numElements > FreqKeyNum)
! {
! int j;
! FreqKeyNum = noise_hash->numElements;
! memcpy((void *)freqKey, (void *)key, NOISE_HISTORY);
! dbg("HashZeroDebug", "Setting most frequent key (%i): ", (int) FreqKeyNum);
! for (j = 0; j < NOISE_HISTORY; j++) {
! dbg_clear("HashZeroDebug", "[%hhu] ", key[j]);
! }
! dbg_clear("HashZeroDebug", "\n");
! }
}
!
! void arrangeKey(uint16_t node_id)__attribute__ ((C, spontaneous))
! {
! int i;
! char key[NOISE_HISTORY];
! char *pKey = noiseData[node_id].key;
!
! for(i=0;i<NOISE_HISTORY-1; i++)
! {
! key[i] = pKey[i+1];
}
! memcpy((void *)pKey, (void *)key, NOISE_HISTORY);
}
! /*
! * After makeNoiseModel() is done, make PMF distribution for each bin.
! */
! void makePmfDistr(uint16_t node_id)__attribute__ ((C, spontaneous))
! {
! int i;
! char *pKey = noiseData[node_id].key;
! char *fKey = noiseData[node_id].freqKey;
!
! FreqKeyNum = 0;
! for(i=0; i<NOISE_HISTORY; i++) {
! pKey[i] = search_bin_num(noiseData[node_id].noiseTrace[i]);
! }
! sim_noise_dist(node_id);
! arrangeKey(node_id);
! for(i = NOISE_HISTORY; i < noiseData[node_id].noiseTraceIndex; i++) {
! if (i == NOISE_HISTORY) {
! printf("Inserting first element.\n");
}
! pKey[NOISE_HISTORY-1] = search_bin_num(noiseData[node_id].noiseTrace[i]);
! sim_noise_dist(node_id);
! arrangeKey(node_id);
}
+
+ dbg_clear("HASH", "FreqKey = ");
+ for (i=0; i< NOISE_HISTORY ; i++)
+ {
+ dbg_clear("HASH", "%d,", fKey[i]);
+ }
+ dbg_clear("HASH", "\n");
}
+ int dummy;
+ void sim_noise_alarm() {
+ dummy = 5;
+ }
+ char sim_noise_gen(uint16_t node_id)__attribute__ ((C, spontaneous))
+ {
+ int i;
+ int noiseIndex = 0;
+ char noise;
+ struct hashtable *pnoiseTable = noiseData[node_id].noiseTable;
+ char *pKey = noiseData[node_id].key;
+ char *fKey = noiseData[node_id].freqKey;
+ double ranNum = RandomUniform();
+ sim_noise_hash_t *noise_hash;
+ noise_hash = (sim_noise_hash_t *)hashtable_search(pnoiseTable, pKey);
! if (noise_hash == NULL) {
! sim_noise_alarm();
! noise = 0;
! dbg_clear("HASH", "(N)Noise\n");
! dbg("HashZeroDebug", "Defaulting to common hash.\n");
! memcpy((void *)pKey, (void *)fKey, NOISE_HISTORY);
! noise_hash = (sim_noise_hash_t *)hashtable_search(pnoiseTable, pKey);
! }
! dbg_clear("HASH", "Key = ");
! for (i=0; i< NOISE_HISTORY ; i++) {
! dbg_clear("HASH", "%d,", pKey[i]);
! }
! dbg_clear("HASH", "\n");
! dbg("HASH", "Printing Key\n");
! dbg("HASH", "noise_hash->numElements=%d\n", noise_hash->numElements);
! if (noise_hash->numElements == 1) {
! noise = noise_hash->elements[0];
! dbg_clear("HASH", "(E)Noise = %d\n", noise);
! return noise;
! }
!
! for (i = 0; i < NOISE_BIN_SIZE - 1; i++) {
! dbg("HASH", "IN:for i=%d\n", i);
! if (i == 0) {
! if (ranNum <= noise_hash->dist[i]) {
! noiseIndex = i;
! dbg_clear("HASH", "Selected Bin = %d -> ", i+1);
! break;
! }
! }
! else if ( (noise_hash->dist[i-1] < ranNum) &&
! (ranNum <= noise_hash->dist[i]) ) {
! noiseIndex = i;
! dbg_clear("HASH", "Selected Bin = %d -> ", i+1);
! break;
! }
! }
! dbg("HASH", "OUT:for i=%d\n", i);
!
! noise = search_noise_from_bin_num(i+1);
! dbg_clear("HASH", "(B)Noise = %d\n", noise);
! return noise;
}
! char sim_noise_generate(uint16_t node_id, uint32_t cur_t)__attribute__ ((C, spontaneous)) {
! uint32_t i;
! uint32_t prev_t;
! uint32_t delta_t;
! char *noiseG;
! char noise;
! prev_t = noiseData[node_id].noiseGenTime;
!
! if ( (0<= cur_t) && (cur_t < NOISE_HISTORY) ) {
! noiseData[node_id].noiseGenTime = cur_t;
! noiseData[node_id].key[cur_t] = search_bin_num(noiseData[node_id].noiseTrace[cur_t]);
! noiseData[node_id].lastNoiseVal = noiseData[node_id].noiseTrace[cur_t];
! return noiseData[node_id].noiseTrace[cur_t];
}
! if (prev_t == 0)
! delta_t = cur_t - (NOISE_HISTORY-1);
! else
! delta_t = cur_t - prev_t;
!
! dbg_clear("HASH", "delta_t = %d\n", delta_t);
!
! if (delta_t == 0)
! noise = noiseData[node_id].lastNoiseVal;
! else {
! noiseG = (char *)malloc(sizeof(char)*delta_t);
!
! for(i=0; i< delta_t; i++) {
! noiseG[i] = sim_noise_gen(node_id);
! arrangeKey(node_id);
! noiseData[node_id].key[NOISE_HISTORY-1] = search_bin_num(noiseG[i]);
}
! noise = noiseG[delta_t-1];
! noiseData[node_id].lastNoiseVal = noise;
!
! free(noiseG);
}
! noiseData[node_id].noiseGenTime = cur_t;
! if (noise == 0) {
! dbg("HashZeroDebug", "Generated noise of zero.\n");
! }
! return noise;
}
! /*
! * When initialization process is going on, make noise model by putting
! * experimental noise values.
! */
! void makeNoiseModel(uint16_t node_id)__attribute__ ((C, spontaneous)) {
int i;
! for(i=0; i<NOISE_HISTORY; i++) {
! noiseData[node_id].key[i] = search_bin_num(noiseData[node_id].noiseTrace[i]);
}
!
! sim_noise_add(node_id, noiseData[node_id].noiseTrace[NOISE_HISTORY]);
! arrangeKey(node_id);
!
! for(i = NOISE_HISTORY; i < noiseData[node_id].noiseTraceIndex; i++) {
! noiseData[node_id].key[NOISE_HISTORY-1] = search_bin_num(noiseData[node_id].noiseTrace[i]);
! sim_noise_add(node_id, noiseData[node_id].noiseTrace[i+1]);
! arrangeKey(node_id);
}
}
Index: sim_noise.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/sim_noise.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** sim_noise.h 5 Mar 2007 19:07:57 -0000 1.1
--- sim_noise.h 1 Apr 2007 00:29:34 -0000 1.2
***************
*** 1,49 ****
/*
! * Copyright (c) 2006 Stanford University.
! * All rights reserved.
! *
! * Redistribution and use in source and binary forms, with or without
! * modification, are permitted provided that the following conditions
! * are met:
! * - Redistributions of source code must retain the above copyright
! * notice, this list of conditions and the following disclaimer.
! * - Redistributions in binary form must reproduce the above copyright
! * notice, this list of conditions and the following disclaimer in the
! * documentation and/or other materials provided with the
! * distribution.
! * - Neither the name of the Stanford University nor the names of
! * its contributors may be used to endorse or promote products derived
! * from this software without specific prior written permission.
*
! * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
! * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
! * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
! * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD
! * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
! * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
! * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
! * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
! * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
! * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
! * OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
! * The C functions for accessing TOSSIM's noise simulation data
! * structures.
*
! * @author Philip Levis
! * @date Mar 2 2007
*/
-
// $Id$
!
! #ifndef SIM_GAIN_H_INCLUDED
! #define SIM_GAIN_H_INCLUDED
!
#ifdef __cplusplus
--- 1,39 ----
/*
! * "Copyright (c) 2005 Stanford University. All rights reserved.
*
! * Permission to use, copy, modify, and distribute this software and
! * its documentation for any purpose, without fee, and without written
! * agreement is hereby granted, provided that the above copyright
! * notice, the following two paragraphs and the author appear in all
! * copies of this software.
! *
! * IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE TO ANY PARTY FOR
! * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
! * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
! * IF STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
! * DAMAGE.
! *
! * STANFORD UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
! * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
! * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
! * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND STANFORD UNIVERSITY
! * HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
! * ENHANCEMENTS, OR MODIFICATIONS."
*/
/**
! * Implementation of all of the SNIST primitives and utility
! * functions.
*
! * @author Hyungjune Lee
! * @date Oct 13 2006
*/
// $Id$
+ #ifndef _SIM_NOISE_HASH_H_
+ #define _SIM_NOISE_HASH_H_
! #include <stdio.h>
#ifdef __cplusplus
***************
*** 51,62 ****
#endif
! void create_model(uint32_t mote, uint32_t sampleRate, uint32_t historyLength);
! void clear_model(uint32_t mote);
! void add_reading(uint32_t mote, double value);
! double getSample(uint32_t mote, sim_time_t time);
!
#ifdef __cplusplus
}
#endif
! #endif // SIM_GAIN_H_INCLUDED
--- 41,86 ----
#endif
! enum {
! NOISE_MIN = -120,
! NOISE_MAX = 10,
! NOISE_MIN_QUANTIZE = -100,
! NOISE_QUANTIZE_INTERVAL = 5,
! NOISE_BIN_SIZE = (NOISE_MAX - NOISE_MIN)/NOISE_QUANTIZE_INTERVAL,
! NOISE_HISTORY = 20,
! NOISE_DEFAULT_ELEMENT_SIZE = 8,
! NOISE_HASHTABLE_SIZE = 8192,
! NOISE_MIN_TRACE = 1024,
! };
!
! typedef struct sim_noise_hash_t {
! char key[NOISE_HISTORY];
! int numElements;
! int size;
! char *elements;
! char flag;
! float dist[NOISE_BIN_SIZE];
! } sim_noise_hash_t;
!
! typedef struct sim_noise_node_t {
! char key[NOISE_HISTORY];
! char freqKey[NOISE_HISTORY];
! char lastNoiseVal;
! uint32_t noiseGenTime;
! struct hashtable *noiseTable;
! char* noiseTrace;
! uint32_t noiseTraceLen;
! uint32_t noiseTraceIndex;
! } sim_noise_node_t;
!
! void sim_noise_init();
! char sim_real_noise(uint16_t node_id, uint32_t cur_t);
! char sim_noise_generate(uint16_t node_id, uint32_t cur_t);
! void sim_noise_trace_add(uint16_t node_id, char val);
! void sim_noise_create_model(uint16_t node_id);
!
#ifdef __cplusplus
}
#endif
! #endif // _SIM_NOISE_HASH_H_
!
Index: sim_tossim.c
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/sim_tossim.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** sim_tossim.c 12 Dec 2006 18:23:35 -0000 1.4
--- sim_tossim.c 1 Apr 2007 00:29:34 -0000 1.5
***************
*** 39,42 ****
--- 39,44 ----
#include <sys/time.h>
+ #include <sim_noise.h> //added by HyungJune Lee
+
static sim_time_t sim_ticks;
static unsigned long current_node;
***************
*** 49,52 ****
--- 51,55 ----
sim_log_init();
sim_log_commit_change();
+ sim_noise_init(); //added by HyungJune Lee
{
Index: tossim.c
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/tossim.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** tossim.c 12 Dec 2006 18:23:35 -0000 1.4
--- tossim.c 1 Apr 2007 00:29:34 -0000 1.5
***************
*** 45,48 ****
--- 45,49 ----
#include <radio.c>
#include <packet.c>
+ #include <sim_noise.h>
uint16_t TOS_NODE_ID = 1;
***************
*** 191,194 ****
--- 192,207 ----
}
+ void Mote::addNoiseTraceReading(int val) {
+ sim_noise_trace_add(id(), (char)val);
+ }
+
+ void Mote::createNoiseModel() {
+ sim_noise_create_model(id());
+ }
+
+ int Mote::generateNoise(int when) {
+ return (int)sim_noise_generate(id(), when);
+ }
+
Tossim::Tossim(nesc_app_t* n) {
app = n;
Index: tossim.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/tossim.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** tossim.h 12 Dec 2006 18:23:35 -0000 1.4
--- tossim.h 1 Apr 2007 00:29:34 -0000 1.5
***************
*** 93,96 ****
--- 93,100 ----
void setID(unsigned long id);
+ void addNoiseTraceReading(int val);
+ void createNoiseModel();
+ int generateNoise(int when);
+
Variable* getVariable(char* name);
Index: tossim.i
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/tossim.i,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** tossim.i 7 Nov 2006 19:31:22 -0000 1.3
--- tossim.i 1 Apr 2007 00:29:34 -0000 1.4
***************
*** 348,351 ****
--- 348,354 ----
Variable* getVariable(char* name);
+ void addNoiseTraceReading(int val);
+ void createNoiseModel();
+ int generateNoise(int when);
};
Index: tossim_wrap.cxx
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/tossim_wrap.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** tossim_wrap.cxx 7 Nov 2006 19:31:22 -0000 1.3
--- tossim_wrap.cxx 1 Apr 2007 00:29:34 -0000 1.4
***************
*** 1,5 ****
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
! * Version 1.3.29
*
* This file is not intended to be easily readable and contains a number of
--- 1,5 ----
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
! * Version 1.3.19
*
[...10014 lines suppressed...]
#endif
! SWIGEXPORT(void) SWIG_init(void) {
! static PyObject *SWIG_globals = 0;
! static int typeinit = 0;
! PyObject *m, *d;
! int i;
! if (!SWIG_globals) SWIG_globals = SWIG_newvarlink();
! m = Py_InitModule((char *) SWIG_name, SwigMethods);
! d = PyModule_GetDict(m);
! if (!typeinit) {
! for (i = 0; swig_types_initial[i]; i++) {
! swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]);
}
! typeinit = 1;
}
! SWIG_InstallConstants(d,swig_const_table);
!
}
More information about the Tinyos-2-commits
mailing list