⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hand_set.c

📁 是zmac的协议的全部完整的解析.代码例子很全
💻 C
📖 第 1 页 / 共 2 页
字号:
// *******************************************************************
//	Hand_Set.c
//	As a router, but use SINK_APP definition.
//
//	Copyright 2006 by Holley Corporation. All rights reserved.		   
// *******************************************************************
#include	"app/sensor/common.h"
#include	"Holley_ext.h"

/****************************************************************************/
/*	注意要配置以下参数:													*/
/*		取消 DISABLE_WATCHDOG												*/
/*		EMBER_SERIAL1_TX_QUEUE_SIZE	= 128									*/
/*		EMBER_SERIAL1_RX_QUEUE_SIZE	= 32									*/
/****************************************************************************/


// ************************************************************************
// Ember endpoint and interface	configuration

int8u						emberEndpointCount = 1;
EmberEndpointDescription	PGM	endpointDescription	= {	PROFILE_ID,	0, };
EmberEndpoint				emberEndpoints[] = {
													{ ENDPOINT,	&endpointDescription },
											   };
// End Ember endpoint and interface	configuration
// *******************************************************************

BOOL		buttonZeroPress	= FALSE;  // for button	push - see halButtonIsr


//int			main( void );
//void			emberIncomingMessageHandler( EmberIncomingMessageType type, EmberApsFrame *apsFrame, EmberMessageBuffer message );
void			emberStackStatusHandler	( EmberStatus status );
static	void	applicationTick( void );
void			checkButtonEvents(void);
//void			halButtonIsr( int8u	button,	int8u state	);

//void			emberMessageSent( int8u	bindingTableIndex, int8u clusterId, EmberMessageBuffer message, EmberStatus status );
//void			emberUnicastSent ( EmberNodeId destination,	EmberApsFrame *apsFrame, EmberMessageBuffer message, EmberStatus status );
//EmberStatus	emberRemoteSetBindingHandler( EmberBindingTableEntry *entry	);
//EmberStatus	emberRemoteDeleteBindingHandler( int8u index );
//void			bootloadUtilQueryResponseHandler( BOOL bootloaderActive, int16u manufacturerId, int8u *hardwareTag, EmberEUI64 targetEui, int8u bootloaderCapabilities, int8u platform, int8u micro, int8u phy, int16u ulversion );
//BOOL			bootloadUtilLaunchRequestHandler( int16u manufacturerId, int8u *hardwareTag, EmberEUI64 sourceEui );

// *******************************************************************

// *******************************************************************

int	main(void)
{
//	EmberNetworkParameters	networkParams;
	EmberResetType			reset;
	EmberStatus				status;

	halInit();			//Initialize the hal

	INTERRUPTS_ON();	// allow interrupts

	#ifdef	HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
		emberSerialInit( APP_SERIAL, BAUD_19200, PARITY_EVEN, 1	);
	#endif

	#ifdef DEBUG
		emberDebugInit(DEBUG_SERIAL);
	#endif

	reset =	halGetResetInfo();
	status = emberInit(reset);	// emberInit must be called	before other EmberNet stack	functions

	if ( status != EMBER_SUCCESS ) 
	{
		#ifdef	HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
			emberSerialGuaranteedPrintf ( APP_SERIAL,
										  "\r\nERROR: Coord emberInit 0x%x\r\n", status );
		#endif

		assert(FALSE);
	} 
	else
	{
		#ifdef	HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
			emberSerialPrintf( APP_SERIAL, "\r\nEVENT: emberInit passed\r\n" );
		#endif
	}

	GPIO_SETL =	BIT(13);			//turn off Led1	 tx	data
	GPIO_SETL =	BIT(14);			//turn off Led2	 rx	data
	GPIO_SETL =	BIT(15);			//turn off Led3
	emberClearBindingTable();

	Sink_Para_Init();

	// Set the security	key	- specific to this application,	all	variants 
	// of this application (sink, sensor, sleepy-sensor, mobile-sensor)
	// need	to use the same	key. This function is in app/sensor/common.c
	setSecurityKey();

	 #ifdef	USE_BOOTLOADER_LIB
		// Using the same port for application serial print	and	passthru 
		// bootloading.	 User must be careful not to print anything	to the port
		// while doing passthru	bootload since that	can	interfere with the data
		// stream.	Also the port's	baud rate will be set to 115200	kbps in	order
		// to maximize bootload	performance.
		bootloadUtilInit(APP_SERIAL, DEBUG_SERIAL);
	#endif // USE_BOOTLOADER_LIB

	#ifdef	HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
		emberSerialWriteString(	APP_SERIAL, "\r\nINIT: HandSet app " );
		printEUI64( APP_SERIAL, (EmberEUI64*) emberGetEui64() );
		emberSerialPrintf( APP_SERIAL, "\r\n" );
		emberSerialWaitSend( APP_SERIAL );
	#endif

	#ifdef	HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
		emberSerialPrintf( APP_SERIAL, "\r\nSet Baud Rate %x\r\n", BAUD_1200 );
	#endif
	if ( emberSerialInit( HOLLEY_SERIAL, BAUD_1200, PARITY_EVEN, 1	) != EMBER_SUCCESS ) 
	{
		#ifdef	HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
			emberSerialPrintf( APP_SERIAL, "\r\nSet Baud Rate %x failed.\r\n", BAUD_1200 );
		#endif
		assert(FALSE);
	}

	// were not able to join the old network
	#ifdef	HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
		emberSerialPrintf( APP_SERIAL, "\r\nHANDSET APP: trying to join a network\r\n" );
		emberSerialWaitSend(APP_SERIAL);
	#endif

	buttonZeroPress = TRUE;		// if not joined with a network, join
	checkButtonEvents();

	while(TRUE)	
	{
		halResetWatchdog();

		emberTick();

		Sink_Store_UART_Data();

		Sink_Process_Buffered_UART_Data();

		Sink_Process_Buffered_RF_Data();

		if ( emberNetworkState() == EMBER_JOINED_NETWORK )
			applicationTick();
		else
		{
			buttonZeroPress = TRUE;
			checkButtonEvents();
		}

		#ifdef DEBUG
			emberSerialBufferTick();	// Needed for debug which uses buffered serial
		#endif
	}
}





void	emberIncomingMessageHandler(	EmberIncomingMessageType type,
										EmberApsFrame *apsFrame,
										EmberMessageBuffer message )
{
	#ifdef USE_BOOTLOADER_LIB
		// If we are in	the	middle of bootloading, then	we want	to limit the
		// radio activity to minimum to	avoid causing any interruptions	to the
		// bootloading process.
		if ( IS_BOOTLOADING ) 
			return;
	#endif

//	if ( type == EMBER_INCOMING_DATAGRAM || type == EMBER_INCOMING_MULTICAST )
	if ( type != EMBER_INCOMING_MULTICAST_LOOPBACK )
	{
		if ( Store_RF_Data( message ) == FALSE )
		{
			#ifdef	HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
				emberSerialPrintf( APP_SERIAL, "\r\nOut	of aucRF_MSG_Index slot. Oldest RF frame is deleted\r\n" );
				emberSerialWaitSend( APP_SERIAL	);
			#endif
		}

		#ifdef	HL_OUTPUT_DEBUG_INFO_VIA_SERIAL

			switch ( apsFrame->clusterId ) 
			{
				case HL_CMD_READ_OD:
					emberSerialPrintf( APP_SERIAL, "\r\nReceive Read_OD Resp+.\r\n"	);
					emberSerialWaitSend( APP_SERIAL	);
					break; 

				case HL_CMD_WRITE_OD:
					emberSerialPrintf( APP_SERIAL, "\r\nReceive Write_OD Resp+.\r\n" );
					emberSerialWaitSend( APP_SERIAL	);
					break; 

				case HL_CMD_STATEMENT:
					emberSerialPrintf( APP_SERIAL, "\r\nReceive Advertise from Sink.\r\n" );
					emberSerialWaitSend( APP_SERIAL	);
					break; 

				case HL_CMD_COLLECT_DATA:
					emberSerialPrintf( APP_SERIAL, "\r\nReceive Collect Data Resp.\r\n"	);
					emberSerialWaitSend( APP_SERIAL	);
					break; 

				case HL_CMD_TRANSFER_MTR:
					emberSerialPrintf( APP_SERIAL, "\r\nReceive Transfer Data Resp.\r\n" );
					emberSerialWaitSend( APP_SERIAL	);
					break;

				case HL_CMD_STATEMENT_ACK:
					emberSerialPrintf( APP_SERIAL, "\r\nReceive Advertise Ack.\r\n"	);
					emberSerialWaitSend( APP_SERIAL	);
					break; 

				case HL_CMD_READ_OD_ERR:
					emberSerialPrintf( APP_SERIAL, "\r\nReceive Read_OD Resp-.\r\n"	);
					emberSerialWaitSend( APP_SERIAL	);
					break; 

				case HL_CMD_WRITE_OD_ERR:
					emberSerialPrintf( APP_SERIAL, "\r\nReceive Write_OD Resp-.\r\n" );
					emberSerialWaitSend( APP_SERIAL );
					break; 
			}

		#endif	// HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
	}
}



// this	is called when the stack status	changes
void	emberStackStatusHandler(EmberStatus	status)
{
	switch (status)	
	{
		case EMBER_NETWORK_UP:
			Set_Multicast_Binding();
			#ifdef	HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
				emberSerialPrintf ( APP_SERIAL,
									"\r\nEVENT: stack Status now EMBER_NETWORK_UP\r\n" );
			#endif
			break;

		case EMBER_NETWORK_DOWN:
			#ifdef	HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
				emberSerialPrintf ( APP_SERIAL,
									"\r\nEVENT: stack Status now EMBER_NETWORK_DOWN\r\n");
			#endif
			break;

		case EMBER_JOIN_FAILED:
			#ifdef	HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
				emberSerialPrintf ( APP_SERIAL,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -