首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在NesC中接收不同类型的消息

如何在NesC中接收不同类型的消息
EN

Stack Overflow用户
提问于 2017-03-20 18:27:28
回答 1查看 184关注 0票数 0

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

我是暂时这么做的

代码语言:javascript
复制
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();
EN

回答 1

Stack Overflow用户

发布于 2017-05-29 23:23:47

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

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

代码语言:javascript
复制
    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];

在你的页眉中,你会看到:

代码语言:javascript
复制
enum 
{
    HELLOMSG = 1,
    VIOSINMSG = 2,
} ;

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

代码语言:javascript
复制
uses interface AMSend as RadioSendHello;
uses interface Receive as RadioReceiveHello;
uses interface AMSend as RadioSendViosin;
uses interface Receive as RadioReceiveViosin;

然后,您可以使用相关的事件处理程序来处理传入的数据包。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42901188

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档