所以在TinyOS中,一個接口由命令組成和事件。當模塊使用接口時,它調用它的命令並提供其事件的實現(提供事件處理程序)。TinyOS事件返回類型含義
命令的返回類型的意義很清楚,它與任何編程語言中的任何函數/方法的意義相同,但事件的返回類型結果不清楚。
讓我們舉個例子:
interface Counter{
command int64_t getCounter(int64_t destinationId);
event int64_t counterSent(int64_t destinationId);
}
讓我們定義一個模塊,提供計數器接口。
module Provider{
provides interface Counter;
}
implementation {
int64_t counter;
counter = 75; //Random number
/**
Returns the value of the counter and signals an event that
someone with id equal to destinationId asked for the counter.
**/
command int64_t getCounter(int64_t destinationId){
int64_t signalReturnedValue;
signalReturnedValue = signal counterSent(destinationId);
return counter;
}
}
現在,讓我們定義兩個模塊,使用這個接口。
module EvenIDChecker{
uses interface Counter;
}
implementation{
/**
Returns 1 if the destinationId is even, 0 otherwise
**/
event int64_t counterSent(int64_t destinationId){
if(destinationId % 2 == 0){
return 1;
} else {
return 0;
}
}
}
現在讓我們來定義它使用相同的接口,但確實的EvenIDChecker模塊的逆另一個模塊。
module OddIDChecker{
uses interface Counter;
}
implementation{
/**
Returns 1 if the destinationId is odd, 0 otherwise
**/
event int64_t counterSent(int64_t destinationId){
if(destinationId % 2 == 1){
return 1;
} else {
return 0;
}
}
}
最終,這將是VAR signalReturnedValue的終值?
當你編譯nesC代碼時,你是否遇到了'調用Counter.counterSent in ... uncombined'的警告? – IvanR