我正试图了解nesC的模块、配置、接口和组件是如何工作的。为了做到这一点,我尝试实现一个非常简单的应用程序;当它完成引导时,它应该打开它的三个LED来显示它的ID。但是我得到了错误:
/home/tinyos/WSN-Project/src/CoolLed/CoolLedM.nc: In function `CL.setCoolLed':
/home/tinyos/WSN-Project/src/CoolLed/CoolLedM.nc:12: Leds.led0On not connected
/home/tinyos/WSN-Project/src/CoolLed/CoolLedM.nc:14: Leds.led0Off not connected我使用了Blink和BlinkToRadio示例作为指南,但没有看到每个led连接。那么,这个错误信息意味着什么呢?我该怎么解决这个问题?
这是我的程序,注释显示它放在哪个文件中。
// AppC.nc
configuration AppC{}
implementation{
components AppM;
components MainC;
AppM.Boot -> MainC;
components CoolLedM;
AppM.CL -> CoolLedM;
}
// AppM.nc
module AppM{
uses interface Boot;
uses interface CoolLedI as CL;
}
implementation{
event void Boot.booted(){
call CL.setCoolLed((uint8_t)TOS_NODE_ID);
}
}
// CoolLedI.nc
interface CoolLedI{
command void setCoolLed(uint8_t mask);
}
// CoolLedC.nc
configuration CoolLedC{}
implementation
{
components CoolLedM;
components LedsC;
CoolLedM.Leds -> LedsC;
}
// CoolLedM.nc
module CoolLedM{
provides interface CoolLedI as CL;
uses interface Leds;
}
implementation{
command void CL.setCoolLed(uint8_t mask){
if(mask & 0x01)
call Leds.led0On();
else
call Leds.led0Off();
...
}
}发布于 2019-04-15 19:17:37
错误说CoolLedM使用接口Leds,但是接口没有连接到任何实现。让我们看看AppC.nc
configuration AppC{}
implementation{
components AppM;
components MainC;
AppM.Boot -> MainC;
components CoolLedM;
AppM.CL -> CoolLedM;
}实际上:您在应用程序中使用了CoolLedM,但是没有定义模块使用的Leds实现。
您还定义了CoolLedC,它确实连接了CoolLedM的Leds接口,但是它有两个问题:
CoolLedC本身不在任何地方使用。CoolLedC不提供任何接口,因此不能真正使用它。要立即解决问题,请将Leds连接到AppC中,就像您在CoolLedC中所做的那样(并删除未使用的CoolLedC):
components LedsC;
CoolLedM.Leds -> LedsC;一个更好和更常见的设计(参见下面的链接)是将CoolLedC定义为一个提供CoolLedI接口的自包含模块。我建议从一些教程开始,以了解更多关于nesC和TinyOS的知识:
https://stackoverflow.com/questions/55687906
复制相似问题