On Jul 24, 2007, at 11:48 AM, J. Ryan Stinnett wrote:
I'm trying to find a way to change the gain of a radio link in
TOSSIM (from CVS) midway through the simulation. I didn't see a
function specifically for changing the gain of a link already
added, so I thought I would remove the original link and re-add it
with a new gain. Something like this in C (this is a bit contrived):
Tossim* t = new Tossim(NULL);
t->radio()->add(0, 1, -50);
t->radio()->add(1, 0, -50);
t->radio()->add(1, 2, -120);
t->radio()->add(2, 1, -50);
for (int i = 0; i < 10000; i++)
t->runNextEvent();
t->radio()->remove(1, 2);
t->radio()->add(1, 2, -50);
for (int i = 0; i < 10000; i++)
t->runNextEvent();
However, I get a segfault when trying to remove the link. I
believe this is because of a bug in sim_gain_remove() when you
remove the link most recently added for a given source. I tried to
fix that, but then I just ended up with other crashes when messages
were trying to be sent and such. Any ideas?
There's a bug in the remove function, pertaining to updating the
linked list on a remove. Try this:
void sim_gain_remove(int src, int dest) __attribute__ ((C,
spontaneous)) {
gain_entry_t* current;
gain_entry_t* prevLink;
int temp = sim_node();
if (src > TOSSIM_MAX_NODES) {
src = TOSSIM_MAX_NODES;
}
sim_set_node(src);
current = sim_gain_first(src);
prevLink = NULL;
while (current != NULL) {
gain_entry_t* tmp;
if (current->mote == dest) {
if (prevLink == NULL) {
connectivity[src] = current->next;
}
else {
prevLink->next = current->next;
}
tmp = current->next;
sim_gain_deallocate_link(current);
current = tmp;
}
else {
prevLink = current;
current = current->next;
}
}
sim_set_node(temp);
}
Phil
_______________________________________________
Tinyos-help mailing list
Tinyos-help@Millennium.Berkeley.EDU
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help