第三章 TinyOS编程语言nesC
第三节 接口
例3.8:通用接口TimeSyncPacket
interface TimeSyncPacket<precision_tag, size_type>{
command bool isValid(message_t* msg);
command size_type eventTime(message_t* msg);
}
通用接口TimeSyncPacket具有两个参数类型,precision_tag和size_type。参数precision_tag标识计时器的精确度类型,接口TimeSyncPacket中的命令和事件没有使用这个参数。参数size_type标识了命令eventTime的返回值类型。
磁力计组件的规范中提供的接口Read也是一个通用接口,接口Read的参数类型为uint16_t。如果将使用Timer<TMilli>接口的组件与提供Timer<TMicro>接口的组件连接起来,则会产生编译错误。
例3.9:MagnetometerC组件
module MagnetometerC{
provides interface StdControl;
provides interface Read<uint16_t>
}