Hello,
msg=(message_t *)btrpkt; is not correct, you are assigning the payload 
to the msg, you can't do that. msg is a pointer to the AMPacket, btrpkt 
is a pointer to the payload within the AMPacket. So your packet is 
alredy set up without the mentioned line of code. You can just send msg 
and your edited payload is already assigned to the msg.

But there is another problem. if you resend the msg, you can't return 
the same one at the end of the Funktion. In that case the Networkstack 
may reuses the memory for a new incoming packet bevore your packet is 
send. you have to define a global msg and return thatone. do something 
like (pseudocode):

bool busy = FALSE;
message_t  firstUnusedMsg;
message_t* pointerToSomeNotUsedMsg = &firstUnusedMsg;

event message_t* Receive.receive(message_t* msg, void* payload, uint8_t 
len){

BlinkToRadioMsg* btrpkt;
if (len != sizeof(BlinkToRadioMsg))
        return msg;
btrpkt = (BlinkToRadioMsg*)payload;

//do what you want with your payload, e.g.:
btrpkt->LedDaAccendere++;

if(busy)
        return msg; //you can't handle it, you need a free msg
else
        busy = TRUE;

if(call AMSend.send(AM_BROADCAST_ADDR,msg,sizeof(BlinkToRadioMsg)) !=
SUCCESS)
        busy = FALSE;

message_t* ret = pointerToSomeNotUsedMsg;
pointerToSomeNotUsedMsg = msg;

return ret;
}

event sendDone(...)
{
if(msg == pointerToSomeNotUsedMsg)
        busy = FALSE;
}

Keep in mind: busy is not a lock for the Networkstack, it is a lock for 
your datastructures, in this example pointerToSomeNotUsedMsg

I strongly recommand the communication tutorial!

I hope i could help,
Jack Porter

Nino Caruso schrieb:
> Hi to all,
> i've  a problem with telosb / tinyos-2.x, it is the sequent:
> 
> event message_t* Receive.receive(message_t* msg, void* payload, uint8_t 
> len){
>    BlinkToRadioMsg* btrpkt;
>    if (len == sizeof(BlinkToRadioMsg)) {
>       btrpkt = (BlinkToRadioMsg*)payload;
>       if(btrpkt->destid==TOS_NODE_ID) {
>       setLeds(btrpkt->LedDaAccendere);
>             btrpkt->LedDaAccendere++;
>             if(btrpkt->LedDaAccendere==3) btrpkt->LedDaAccendere=0;
>             btrpkt->destid=1;
>             btrpkt->sourceid=TOS_NODE_ID;
>           }
>             }
>    if(!busy){
>    msg=(message_t *)btrpkt;
>    if(call AMSend.send(AM_BROADCAST_ADDR,msg,sizeof(BlinkToRadioMsg)) == 
> SUCCESS) busy=TRUE;
>    }
>    return msg;
>        }
> }
> 
> my problem is that the mote don't send any packet , maybe there is 
> something in the build of the msg before call AMSend, i don't know how 
> to put the structure in a variable message_t like msg.
> 
> 
> specify that : BlinkToRadioMsg is a structure :
> typedef nx_struct BlinkToRadioMsg {
>   nx_uint8_t sourceid;
>   nx_uint8_t destid;
>   nx_uint8_t LedDaAccendere;
> } BlinkToRadioMsg;
> 
> thank you so much
> 
> 
> -- 
> Nino Caruso <[email protected] 
> <mailto:[email protected]>>
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to