0

I'm a bigginer in NesC langage and I want to learn how to reveive diffrent messages, in my case I have to send hello msg and other type of msg but at the reception I don't know how to specify the received msg if it is a hello ar other

I did this for the moment

event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len) {
msg_voisin *voi= (msg_voisin*)payload;
Hello *omsg = (Hello*)payload;
printInt8(len); 
printStr("***");
report_received();
KillaKem
  • 995
  • 1
  • 13
  • 29
lyly
  • 1
  • 1

1 Answers1

0

The receive event will only be run once it has received the type of message it is listening for, and that type is specified in the application configuration file.

So in your Configuration file you would have:

    components ApplicationNameP as App, ActiveMessageC;
    components new AMSenderC(HELLOMSG) as HELLOMsgSender;
    components new AMSenderC(VIOSINMSG) as VIOSINMsgSender;
    App.RadioSendHello -> HELLOMsgSender;
    App.RadioReceiveHello -> ActiveMessageC.Receive[HELLOMSG];
    App.RadioSendViosin -> VIOSINMsgSender;
    App.RadioReceiveViosin -> ActiveMessageC.Receive[VIOSINMSG];

In your header you would have:

enum 
{
    HELLOMSG = 1,
    VIOSINMSG = 2,
} ;

and in you application file you would have:

uses interface AMSend as RadioSendHello;
uses interface Receive as RadioReceiveHello;
uses interface AMSend as RadioSendViosin;
uses interface Receive as RadioReceiveViosin;

you can then use the relevant event handlers to process the packets as they come in.

KillaKem
  • 995
  • 1
  • 13
  • 29