【问题标题】:how to receive diffrent types of messages in NesC如何在 NesC 中接收不同类型的消息
【发布时间】:2017-03-20 10:27:27
【问题描述】:

我是 NesC 语言的大佬,我想学习如何接收不同的消息,在我的情况下,我必须发送 hello msg 和其他类型的 msg,但在接待处我不知道如何指定接收到的消息msg 如果是 hello ar other

我暂时这样做了

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();

【问题讨论】:

    标签: tinyos nesc


    【解决方案1】:

    接收事件只有在接收到它正在侦听的消息类型后才会运行,并且该类型在应用程序配置文件中指定。

    因此,在您的配置文件中,您将拥有:

        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];
    

    在您的标题中,您将拥有:

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

    在您的应用程序文件中,您将拥有:

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

    然后,您可以使用相关的事件处理程序在数据包进入时对其进行处理。

    【讨论】:

      猜你喜欢
      • 2017-01-20
      • 2012-04-08
      • 1970-01-01
      • 2012-07-27
      • 1970-01-01
      • 2020-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多