📄 hand_set.c
字号:
"\r\nEVENT: stack Status now EMBER_JOIN_FAILED\r\n");
#endif
buttonZeroPress = TRUE;
checkButtonEvents();
break;
default:
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialPrintf ( APP_SERIAL, "\r\nEVENT: stackStatus now 0x%x\r\n", status);
#endif
break;
}
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialWaitSend(APP_SERIAL);
#endif
}
/****************************************************************************/
/* 在本函数中完成以下功能: */
/* 1. 过时绑定表的清理 */
/****************************************************************************/
static void applicationTick( void )
{
static int16u lastBlinkTime = 0;
static int8u ucCount = 4;
int16u time;
int8u i;
EmberStatus status;
EmberBindingTableEntry entry;
#ifdef USE_BOOTLOADER_LIB
bootloadUtilTick();
#endif
time = halCommonGetInt16uMillisecondTick();
if ( time - lastBlinkTime > 120 )
GPIO_SETL = BIT(15); //turn OFF Led3
if ( time - lastBlinkTime > 250 )
{
lastBlinkTime = time;
GPIO_CLRL = BIT(15); //turn on Led3 HeartBeat
ucCount --;
if ( ucCount == 0 ) // 调整实时时间
{
Adjust_ucCurrent_Time( &sCurrent_Time );
ucCount = 4;
}
if ( ucReset_Token > 0 )
{
switch ( ucReset_Token ) // 判断是否需要将 Token 恢复为缺省值
{
case 2:
halCommonSetToken( TOKEN_HL_NETWORK_PARA,(int8u*)&sHL_Network_Para );
break;
case 1:
halCommonSetToken( TOKEN_HL_AMR_PARA_GATEWAY,(int8u*)&sHL_AMR_Para_Gateway );
break;
default:
break;
}
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialPrintf( APP_SERIAL, "\r\nReset Token %x to default value.\r\n", ucReset_Token );
#endif
ucReset_Token --;
}
for ( i=0; i<EMBER_BINDING_TABLE_SIZE-1; i++ ) // 删除长时间未使用的绑定
{
status = emberGetBinding( i, &entry );
if ( ( status == EMBER_SUCCESS ) && ( entry.type == EMBER_UNICAST_BINDING ) )
{
ticksSinceLastHeard[i] ++;
if ( ticksSinceLastHeard[i] > HL_BIND_TABLE_RELEASE_GAP )
{
status = emberDeleteBinding(i);
ticksSinceLastHeard[i] = 0;
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialPrintf ( APP_SERIAL,
"\r\nEVENT: too long since last heard, " );
emberSerialPrintf ( APP_SERIAL,
"\r\ndeleting binding table index %x, status %x\r\n", i, status );
#endif
}
}
}
if ( buttonZeroPress )
{
buttonZeroPress = FALSE;
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialPrintf ( APP_SERIAL, "\r\nBUTTON0 Pressed\r\n" );
#endif
}
}
}
void checkButtonEvents(void)
{
EmberNetworkParameters networkParams;
EmberStatus status;
if (buttonZeroPress)
{
buttonZeroPress = FALSE;
switch ( emberNetworkState() ) // if not joined with a network, join
{
case EMBER_NO_NETWORK:
#ifdef USE_HARDCODED_NETWORK_SETTINGS
Read_OD( HL_NETWORK_PARAMETER_INDEX, 0, aucSwam );
networkParams.panId = Get_BIT16_Value( aucSwam + 20 );
networkParams.radioTxPower = aucSwam[3];
networkParams.radioChannel = aucSwam[0];
#else
networkParams.radioTxPower = +3;
scanUtilFindActiveNetwork ( &( networkParams.radioChannel ),
&( networkParams.panId ) );
#endif
status = emberJoinNetwork( EMBER_ROUTER,
&networkParams,
USE_KEY_WHEN_JOINING );
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialPrintf ( APP_SERIAL,
"\r\njoining, channel 0x%x, panid 0x%2x\r\n",
networkParams.radioChannel, networkParams.panId );
emberSerialWaitSend( APP_SERIAL );
if (status != EMBER_SUCCESS)
{
emberSerialPrintf ( APP_SERIAL,
"\r\nerror returned from emberJoin: 0x%x\r\n", status );
}
else
{
emberSerialPrintf(APP_SERIAL, "\r\nwaiting for stack up...\r\n");
}
#endif
break;
case EMBER_JOINING_NETWORK: // if in the middle of joining, do nothing
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
// emberSerialPrintf( APP_SERIAL, "\r\nApp already trying to join\r\n" );
#endif
break;
case EMBER_JOINED_NETWORK: // if already joined, turn allow joining on
emberPermitJoining(0xff); // turn allow join on
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialPrintf(APP_SERIAL, "\r\nTurn permit join ON.\r\n");
#endif
break;
case EMBER_LEAVING_NETWORK: // if leaving, do nothing
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialPrintf(APP_SERIAL, "\r\nApp leaving, no action\r\n");
#endif
break;
}
}
}
void halButtonIsr( int8u button, int8u state )
{
if ( button == BUTTON0 && state == BUTTON_PRESSED )
buttonZeroPress = TRUE;
}
// Called when a message has completed transmission --
// status indicates whether the message was successfully
// transmitted or not.
void emberMessageSent( int8u bindingTableIndex,
int8u clusterId,
EmberMessageBuffer message,
EmberStatus status )
{
}
void emberUnicastSent( EmberNodeId destination,
EmberApsFrame *apsFrame,
EmberMessageBuffer message,
EmberStatus status )
{
}
EmberStatus emberRemoteSetBindingHandler( EmberBindingTableEntry *entry )
{
return EMBER_INVALID_BINDING_INDEX;
}
EmberStatus emberRemoteDeleteBindingHandler( int8u index )
{
return EMBER_INVALID_BINDING_INDEX;
}
#ifdef USE_BOOTLOADER_LIB
// When a device sends out a bootloader query, the bootloader
// query response messages are parsed by the bootloader-util
// libray and and handled to this function. This application
// simply prints out the EUI of the device sending the query
// response.
void bootloadUtilQueryResponseHandler( boolean bootloaderActive,
int16u manufacturerId,
int8u *hardwareTag,
EmberEUI64 targetEui,
int8u bootloaderCapabilities,
int8u platform,
int8u micro,
int8u phy,
int16u ulversion )
{
emberSerialPrintf(APP_SERIAL,"RX [BL QUERY RESP] eui: ");
printEUI64(APP_SERIAL, (EmberEUI64*)targetEui);
emberSerialPrintf(APP_SERIAL," running %p\r\n",
bootloaderActive ? "bootloader":"stack");
emberSerialWaitSend(APP_SERIAL);
}
// This function is called by the bootloader-util library
// to ask the application if it is ok to start the bootloader.
// This happens when the device is meant to be the target of
// a bootload. The application could compare the manufacturerId
// and/or hardwareTag arguments to known values to enure that
// the correct image will be bootloaded to this device.
BOOL bootloadUtilLaunchRequestHandler( int16u manufacturerId,
int8u *hardwareTag,
EmberEUI64 sourceEui)
{
// TODO: Compare arguments to known values.
// TODO: Check for minimum required radio signal strength (RSSI).
// TODO: Do not agree to launch the bootloader if any of the above conditions
// are not met. For now, always agree to launch the bootloader.
return TRUE;
}
#endif // #ifdef USE_BOOTLOADER_LIB
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -