【问题标题】:interface with events and commands - cannot signal event与事件和命令的接口 - 无法发出事件信号
【发布时间】:2013-03-11 21:28:51
【问题描述】:

我发现很难在 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

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

【问题讨论】:

    标签: nesc


    【解决方案1】:

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

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

    试试

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

    [更新]

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

    default event MyInterface.actionDone[foo]() {
        return;
    }
    

    【讨论】:

    • 这是我的错误,应该有(并且在我的真实代码中有!)App 而不是 MyC。但这不是原因……
    • 我想那也应该是-> MC.MyInterface...
    • 好吧,又是我的错。它应该是 MC 而不是 MS。我在这里重新输入代码时可能还犯了一些其他小错误。但这不是错误MyInterface.actionDone not connected 的原因。它不是解析错误或未定义的符号,而是“更深层次”的东西。问题出在接口和组件布线的某个地方,但我不知道在哪里。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多