Hi David,
after using your important previous suggestions, the program was running in a
properly way on 2 motes for testing. But it is correct only if i create packets
by myself and i receive packets by other nodes. If i try to forward i cannot.
Before using Flash, my code was running properly on my motes but the problem
was of insufficient memory as you know well. And i checked it also by
simulations in TOSSIM.
Now, i don't understand why my code seems unable to have the same past
behaviour.
i mean:
in my program every TOT seconds i create a new packet in each node and i
broadcast it. Every node stores this packet in a buffer (different buffers for
different generation periods) where i make some calculations (by using matrix)
and then, if a random parameter allows me, i forward a coded packet, which is a
combination of the previous ones stored in the same buffer.
But now, by using flash, my program is no more able to recognize the innovative
packets->the packets which increase the rank of my matrix->which carry new
information to my node.
May be it's wrong the way i read in Flash.
When i create a new packet, i send it and i write the corrispondent buffer in
flash. When i receive, i check if my packet belongs to the same generation of a
buffer i've already created, so i read from flash, or i write on flash a new
buffer. But however after reading from flash i need to re-write on flash. Is it
possible?notice that after the event FlashBridge.writeDone() i flush on flash.
However when i save my buffers on flash, i save many fields, for example:
typedef struct Buffer{
double _sendallowed;
struct Buffer *next;
int _sendcount;
int _recvcount;
uint8_t _gen;
struct Datagram *generated_;
long generated_rank_;
/* content matrix and rank at last gaussian reduction */
unsigned char **matrix;
long _rank;
int _num_cols;
int _used_cols;
bool _innovative;
/* rows that can already be decoded */
int *_decoded;
int label[block_size];
}Buffer;
but when i call the read's function, i return the cast "(Buffer *)" of the
"void *buffer" specified in the interface.
So for example in my program i have:
task void readFlash(){
if (!call FlashBridge.read(flashAddr,flashBuffer,flashLen)){
post readFlash();
}
}
Buffer* readInToFlash(uint32_t addr, uint32_t len){
flashAddr=addr;
//flashBuffer=buf;
flashLen=len;
post readFlash();
return (Buffer *)flashBuffer;
}
event void FlashBridge.readDone(uint32_t addr, void *buf, uint32_t len,
result_t result){
return;
}
where in my main for example, in the receive part, i do:
event TOS_MsgPtr ReceiveDataNC.receive(TOS_MsgPtr m){
Datagram *dg=(Datagram *)m->data;
int new_decoded,i_new;
double inc,sc,frac;
unsigned char *recbuffer = NULL;
bool is_in_flash;
Buffer *ibuff = NULL;
Buf_flash *b;
is_in_flash=FALSE;
no_received+=1;
dbg(DBG_USR1,"rx from node %i\n, gen %i\n, pckId %i\n, n tot dec
%i\n",dg->saddr,dg->_gen,dg->pckID,decod);
/******************************************
/* node_insert(dg);
/*******************************************/
b=Head;
while((b && b->next!=NULL) && b->gen!=dg->_gen)
b=b->next;
if (!b || b->gen!=dg->_gen){//it doesn't exist in flash,now check in RAM
ibuff = init_NCBuffer(dg->_gen, dg->len);
}
else{//there is in flash
/* we have to read from Flash*/
is_in_flash=TRUE;
ibuff=(Buffer *)calloc(1,sizeof(Buffer));
ibuff=readInToFlash(b->addr_flash,b->len);
}
inc_recvcount(ibuff);
inject(dg,ibuff);
if (ibuff->_innovative) {
inn++;
//dbg(DBG_USR1,"num innovative pcks rx: %i\n",inn);
inc = 0;
sc = calc_send_count();
if (probabilistic_nc) {
frac = modf(sc, &inc); //function: sc's fractional part in frac
(ex.0.8),integer one (ex.0) in inc
j=((double)(call Random.rand())/(double)(0xffff));
if (j < frac)
inc += 1.0;
}
else {
// send own packets at least once
inc = sc;
if (dg->saddr == TOS_LOCAL_ADDRESS && inc < 1)
inc = 1.0;
}
inc_sendallowed(ibuff,inc);
}
/******************/
/* end node_insert*/
/******************/
if (ibuff->_innovative) {
new_decoded = 0;
for (i_new = 0; i_new < block_size; ++i_new) {
// update stats for newly decodable packets
if (ibuff->_decoded[i_new] == 1) {
++new_decoded;
++decod;
recbuffer=recover(ibuff,i_new);
if (recbuffer)
free(recbuffer);
}
}
}
/* now putting on flash the modified buffer*/
if(!is_in_flash){
memcpy(buffer,ibuff,sizeof(Buffer));
post writeToFlash();
}
else{
b->priority=priority(ibuff);
memcpy(buffer,ibuff,sizeof(Buffer));
post writeToFlash();
}
free(ibuff);
return m;
}
So by the inject function, i must expect that i receive buf->innovative=TRUE.
This happens without using flash. Do i might use the read function in a wrong
way?or i cannot re-obtain the same fields of the buffer i wrote before on flash?
I cannot find the solution...
PS here there is the write on flash:
task void writeToFlash() {
Buf_flash *b,*c;
uint32_t A;
b=Head;
while((b && b->next!=NULL) && b->gen!=buffer->_gen)
b=b->next;
if (!b || b->gen!=buffer->_gen){
A=flashWriteAddress;
}
else{
A=b->addr_flash;
}
// Write the entire buffer to flash.
if(!call FlashBridge.write(A,buffer, sizeof(buffer))){
//FAIL, try again
post writeToFlash();
}
else{
if (!b || b->gen!=buffer->_gen){
c=(Buf_flash *)calloc(1,sizeof(Buf_flash));
c->gen=buffer->_gen;//i take these info from the buffer and then i free it
c->addr_flash=flashWriteAddress;
c->len=sizeof(buffer);
c->priority=priority(buffer);
add_element(c);
flashWriteAddress += sizeof(Buffer);
}
/*else{
b->priority=priority(buffer);
b->addr_flash=flashWriteAddress;
}*/
//flashWriteAddress += sizeof(Buffer);
}
}
event void FlashBridge.writeDone(uint32_t addr, void *buf, uint32_t
len,result_t result) {
//Buffer *buff;
//buff=NULL;
if(result) {
/* SUCCESS! update our write location to the next page, or something.
Note that if we only erased sector 0 on boot, anything after
address 0x10000 (the 257'th page on flash')
may not be valid to write to */
//flashWriteAddress += len;
call Leds.redToggle();
call FlashBridge.flush();
}
}
i use it both to write a new buffer or to rewrite an old one...
Any helps are really appreciated!
cheers
Daniele
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help