1

我发现很难在 nesC 中发出事件信号。任何人都可以帮忙吗?(编辑:我在下面的代码中省略了 MainC 组件)。

我定义了一个简单的接口:

interface MyInterface {
    command uint8_t action();
    event void actionDone();
}

它有一个动作和一个事件。

更重要的是,我有一个提供 MyInterface 的组件:

configuration MyComponentC {
    provides interface MyInterface[uint8_t id];
}
implementation {
    components MyComponentM;
    MyInterface = MyComponentM.MyInterface;
}


module MyComponentM {
    provides interface MyInterface[uint8_t id];
}
implementation {
    command uint8_t MyInterface.action[uint8_t id]() {...}
    ...
    event void bar() {
        signal MyInterface.actionDone[foo]();
    }
}

事件栏来自完全不同的界面。在这种情况下,我想用 id == foo 发出事件 actionDone 的信号。

我还有“主要”组件:

configuration MyAppC {
}
implementation {
    components MyC as App;
    components MyComponentC as MC;
    App.MyInterface -> MC.MyInterface[unique("Hello")];
}

module MyC {
    uses interface MyInterface;
}
implementation {
    event void MyInterface.actionDone() {...}
}

但是在编译过程中出现错误:

MyInterface.actionDone not connected

我在哪里做错了?如何正确连接组件?

4

1 回答 1

1

不确定这是否是原因,但在您的应用程序中尝试通过别名引用 MyC,即代替

MyC.MyInterface -> MS.MyInterface[unique("Hello")];

尝试

App.MyInterface -> MS.MyInterface[unique("Hello")];

[更新]

如此链接中所述,由于您使用的是参数化接口,并且无法保证所有 256 个实例都将连接到您需要在 MyComponentM 模块中提供默认实现的东西

default event MyInterface.actionDone[foo]() {
    return;
}
于 2013-03-11T22:07:09.737 回答