· Add “stub_aps.c” and “stub_aps.h” files in the NWK directory of your project. You can locate these files in “ZStack-XXXX\Components\stack\nwk”.
· Include “stub_aps.h” in “GenericApp.c” and “OSAL_GenericApp.c” (“#include "stub_aps.h"”)
· In “OSAL_GenericApp.c” add the red lines:
const pTaskEventHandlerFn tasksArr[] = {
macEventLoop,
nwk_event_loop,
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
GenericApp_ProcessEvent,
StubAPS_ProcessEvent
};
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++ );
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
GenericApp_Init( taskID++ );
StubAPS_Init( taskID );
}
· In “GenericApp.c” in function “void GenericApp_Init( byte task_id )” add:
// Fill out the endpoint description.
GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT;
GenericApp_epDesc.task_id = &GenericApp_TaskID;
GenericApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&GenericApp_SimpleDesc;
GenericApp_epDesc.latencyReq = noLatencyReqs;
// INTERPAN - Register the endpoint description for INTERPAN
StubAPS_RegisterApp( &GenericApp_epDesc );
// Register the endpoint description with the AF
afRegister( &GenericApp_epDesc );
To send an menssage
void GenericApp_INTERPAN( void )
{
/* Seleciona do canal do interpan */
StubAPS_SetInterPanChannel( 0x19 );
/* Buffer com o IEEE MAC Address, cria-se o buffer de traz pra frente */
uint8 buffadd[8] = {0xF3,0x22,0x07,0x01,0x00,0x4B,0x12,0x00};
/* Definições do modo de envio, com endereço 64bit e endpoint INTERPAN */
GenericApp_DstAddr.addrMode = afAddr64Bit;
GenericApp_DstAddr.endPoint = STUBAPS_INTER_PAN_EP;
/* Copia o buffer para o endereço do destino */
(void)osal_memcpy(GenericApp_DstAddr.addr.extAddr, buffadd, Z_EXTADDR_LEN);
/* PAN de destino */
GenericApp_DstAddr.panId = 0x6666;
/* Mensagem */
char theMessageData[] = "0";
valorEnv++;
/* Envio */
if ( AF_DataRequest( &GenericApp_DstAddr, &GenericApp_epDesc,
GENERICAPP_CLUSTERID,
(byte)osal_strlen( theMessageData ) + 1,
(byte *)&theMessageData,
&GenericApp_TransID,
AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
{
/* Verifica se a aplicação INTERPAN foi enviada */
if (StubAPS_InterPan(6666, STUBAPS_INTER_PAN_EP))
{
HalLcdWriteStringValue( "InterPan Env", valorEnv, 10, HAL_LCD_LINE_1 );
}
}
else
{
// Error occurred in request to send.
}
/* Volta o canal para IntraPAN */
StubAPS_SetIntraPanChannel();
}