On Thu, 2005-11-17 at 12:11 +0000, Alex Mason wrote:
> Hi,
>
> I am trying to perform some action on the receive event. Nothing was
> working, so I tried writing a small program that just sends a message every
> second. So I thought, I'll light the green LED to signify when a message
> has been received. So, the relevant code for this that I have:
>
>
> USES: interface Receive;
>
>
> event TOS_MsgPtr Receive.receive(TOS_MsgPtr msg, void* payload, uint16_t
> payloadLen) {
> TOS_MsgPtr pMsg;
>
> // msg should have been received - toggle LED
> call Leds.greenToggle();
>
> return pMsg;
> }
>
> To me that looks simple and should work, but hopefully someone can enlighten
> me!
You're passing an uninitialized pointer off of the stack. The radio
stack is going to use this pointer to receive the next packet.
Meanwhile, you're dropping the pointer it passed you, so the packet
buffer it points to is lost.
This is a similar but different example, but in C with read(2):
// Lose the allocated memory
int test(int len) {
myRead((char*)malloc(sizeof(char)) * len, len);
}
// Read into an uninitialized pointer
int myRead(char* buf, int len) {
char* pBuf;
read(pBuf, len);
}
Perhaps what you want is this:
event TOS_MsgPtr Receive.receive(TOS_MsgPtr msg, void* payload, uint16_t
len) {
call Leds.greenToggle();
return msg;
}
or, with a buffer swap:
TOS_Msg buf;
TOS_MsgPtr mptr = &buf;
event TOS_MsgPtr Receive.receive(TOS_MsgPtr msg, void* payload, uint16_t
len) {
TOS_MsgPtr tmp = mptr;
mptr = msg;
call Leds.greenToggle();
return tmp;
}
I'd suggest going through the TinyOS tutorials, or reading the
Receive/ReceiveMsg interface documentations.
Phil
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help