1. 简介
作为一个Z3.0认证要求,所有的ZigBee路由设备(协调员、路由器)必须支持Green Power Basic proxy,一个可以从GPD向GP Sink设备传递命令的应用程序。
一个GPD是一个具有Power限制或依靠能量收集来运作的设备,它不能执行两种通信方式来建立与ZigBee网络的关联。这些GPD使用sInter-PAN frames本身到网络或命令传递。运作方式和GPD命令支持的类型将取决于其能力和资源。
基本代理要求实现GP stub和GP cluster。GP stub 处理Inter-PAN命令并将它们传递给GP设备应用程序。为了确定的运作方法,它也发送数据帧到GP的GPD。GP stub定义的方式可以在设置不同的应用程序开始。GP是在ZigBee预留端点242中实现的。
2. Green Power Basic Proxy
由于Green Power Basic Proxy 是一个将命令转发给Sink 设备的应用程序,所以它没有提供一个需要由实际的应用程序在Basic Proxy设备中运行的函数来实现的功能。此功能唯一的接口是以下内容:
gp_registergpchangechannelreqcb():注册一个回调在应用程序中,这个回调被用来操作切换频道的GPD的信道进行GPD的运作过程中最大时间间隔:gpbirectionalcommissioningchangechanneltimeout(5秒)。
如果应用程序操作不能被中断,注册的回调可以返回false,不允许通道的更改。BDB模块也在向应用程序检查操作。如果应用程序返回true或未注册回调,则 Green Power Basic Proxy应用程序将处理通道的更改。
PS:
ZigBee Green Power Device (ZGPD): This is a source node that sends GreenPower frames into the network via a proxy node.
ZigBee Green Power Proxy (ZGPP): This is a network node which is capableof receiving a Green Power frame from a ZGPD, embedding (tunnelling) theGP frame within a normal ZigBee frame and passing this frame into the ZigBeePRO network.
ZigBee Green Power Sink (ZGPS): This is a sink (target) node which is pairedwith a ZGPD, and is capable of receiving and interpreting tunnelled GP framesas well as direct GP frames from the ZGPD.
3.具体使用
1.主结构中加入gp_event_loop:
const pTaskEventHandlerFn tasksArr[] = {
macEventLoop,
nwk_event_loop,
#if (ZG_BUILD_RTR_TYPE)
gp_event_loop,
#endif
Hal_ProcessEvent,
#if defined( MT_TASK )
MT_ProcessEvent,
#endif
APS_event_loop,
#if defined ( ZIGBEE_FRAGMENTATION )
APSF_ProcessEvent,
#endif
ZDApp_event_loop,
#if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )
ZDNwkMgr_event_loop,
#endif
#ifdef BDB_UPDATE
//Added to include TouchLink functionality
#if defined ( INTER_PAN )
StubAPS_ProcessEvent,
#endif
// Added to include TouchLink initiator functionality
#if defined ( BDB_TL_INITIATOR )
touchLinkInitiator_event_loop,
#endif
// Added to include TouchLink target functionality
#if defined ( BDB_TL_TARGET )
touchLinkTarget_event_loop,
#endif
#endif
zcl_event_loop,
bdb_event_loop,
zclGenericApp_event_loop
};
2.GP初始化 gp_Init
void osalInitTasks( void )
{
uint8 taskID = 0;
tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt);
osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt));
macTaskInit( taskID++ );
nwk_init( taskID++ );
#if (ZG_BUILD_RTR_TYPE)
gp_Init( taskID++ );
#endif
Hal_Init( taskID++ );
#if defined( MT_TASK )
MT_TaskInit( taskID++ );
#endif
APS_Init( taskID++ );
#if defined ( ZIGBEE_FRAGMENTATION )
APSF_Init( taskID++ );
#endif
ZDApp_Init( taskID++ );
#if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )
ZDNwkMgr_Init( taskID++ );
#endif
// Added to include TouchLink functionality
#if defined ( INTER_PAN )
StubAPS_Init( taskID++ );
#endif
// Added to include TouchLink initiator functionality
#if defined( BDB_TL_INITIATOR )
touchLinkInitiator_Init( taskID++ );
#endif
// Added to include TouchLink target functionality
#if defined ( BDB_TL_TARGET )
touchLinkTarget_Init( taskID++ );
#endif
zcl_Init( taskID++ );
bdb_Init( taskID++ );
zclGenericApp_Init( taskID );
}
3.具体函数回调注册:
extern void gp_RegisterGPChangeChannelReqCB(gpChangeChannelReq_t gpChangeChannelReq);
extern void gp_RegisterCommissioningModeCB(gpCommissioningMode_t gpCommissioningMode);
在zclSampleLight_Init中添加:
//GP_UPDATE
#if (ZG_BUILD_RTR_TYPE)
gp_RegisterCommissioningModeCB(gp_CommissioningMode);
gp_RegisterGPChangeChannelReqCB(gp_ChangeChannelReq);
#endif
查看具体一点的函数细节:
#if (ZG_BUILD_RTR_TYPE)
/*********************************************************************
* @fn gp_CommissioningMode
*
* @brief Callback that notifies the application that gp Proxy is entering
* into commissioning mode
*
* @param isEntering -
*
* @return
*/
static void gp_CommissioningMode(bool isEntering)
{
if(isEntering)
{
//Led on indicating enter commissioning mode
}
else
{
//Led off indicating enter commissioning mode
}
}
//GP_UPDATE
/*********************************************************************
* @fn gp_ChangeChannelReq
*
* @brief Callback function to notify the application about a GP commissioning
* request that will change the current channel for at most
* gpBirectionalCommissioningChangeChannelTimeout ms
*
* @param channel - Channel in which the commissioning will take place
*
* @return TRUE to allow change channel, FALSE to do not allow
*/
static uint8 gp_ChangeChannelReq(void)
{
bool allowChangeChannel = TRUE;
//Check application state to decide if allow change channel or not
return allowChangeChannel;
}
#endif
大致就是这样。细心的人发现一件事,你会发现协议栈中包含了两个文件:cGP_stub.h 和dGP_stub.h。自己想一想怎么回事。