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

📄 network.c

📁 通过5120芯片实现无线键盘进行数据的传输功能
💻 C
📖 第 1 页 / 共 4 页
字号:
	/* Transmit the data */	eStatus = eJenie_SendData(u64Address, pu8Data, u16Length, TXOPTION_ACKREQ);	/* Network debugging */	#if NETWORK_DEBUG		if (bUartUp)		{			if (bNetwork_IsString(u16Length, pu8Data))			{				/* Debug with data */				vPrintf("eJenie_SendData(%x:%x, \"%s\", %d, %x) = %s\n",								(uint32) (u64Address >> 32),								(uint32) (u64Address  & 0xFFFFFFFF),								(char *) pu8Data,								u16Length,								TXOPTION_ACKREQ,								aszStatusCode[eStatus]);			}			else			{				/* Debug without data */				vPrintf("eJenie_SendData(%x:%x, %d, %x) = %s\n",								(uint32) (u64Address >> 32),								(uint32) (u64Address  & 0xFFFFFFFF),								u16Length,								TXOPTION_ACKREQ,								aszStatusCode[eStatus]);			}		}	#endif	return eStatus;	/**< \return Status code from eJenie_SendData() */}/**************************************************************************** * * NAME	 		vNetwork_Rx *//*! *\DESCRIPTION	Receive data from network - independent of service. * * This function is called by vNetwork_StackDataEvent() when a data message * has been received from an address, no service is used. * * This function is used to implement to binding permission protocol. *//* RETURNS: * None * ****************************************************************************/PUBLIC void vNetwork_Rx	(	uint64 u64Address, 	/**< Address data received from */	uint16 u16Length, 	/**< Length of data */	uint8 *pu8Data)		/**< Pointer to data */{	/* Network debugging */	#if NETWORK_DEBUG		if (bUartUp)		{			if (bNetwork_IsString(u16Length, pu8Data))			{				/* Debug with data */				vPrintf("vNetwork_Rx(%x:%x, %d, \"%s\")\n",								(uint32) (u64Address >> 32),								(uint32) (u64Address  & 0xFFFFFFFF),								u16Length,								(char *) pu8Data);			}			else			{				/* Debug with data */				vPrintf("vNetwork_Rx(%x:%x, %d)\n",								(uint32) (u64Address >> 32),								(uint32) (u64Address  & 0xFFFFFFFF),								u16Length);			}		}	#endif	/* Does this look like an binding protocol message ? */	if (pu8Data[0] == '<' && pu8Data[1] == 'B')	{		/* Handle the binding message */		vNetwork_Service_BindRx(u64Address, u16Length, pu8Data);	}	else	{		/* PROCESS DATA HERE */		;	}}/**************************************************************************** * * NAME	 		eNetwork_Sleep *//*! *\DESCRIPTION	Go to sleep. *//* RETURNS: * None * ****************************************************************************/PUBLIC teJenieStatusCode eNetwork_Sleep	(	uint32 u32SleepPeriodMs, 	/**< Length of time to sleep for (ms) */	bool_t bMemHold) 			/**< Memory hold */{	teJenieStatusCode  eStatus = E_JENIE_ERR_INVLD_PARAM;	/* Are we an end device ? */	if (eNetwork_DeviceType() == E_JENIE_END_DEVICE)	{		/* Disable wake timer 1 interrupt so we don't get woken from sleeping */		vJPI_WakeTimerEnable(E_JPI_WAKE_TIMER_1, FALSE);		/* Set the sleep period (this is set in ms) */		(void) eJenie_SetSleepPeriod(u32SleepPeriodMs);		/* Go to sleep */		eStatus = eJenie_Sleep(bMemHold);		/* Network debugging */		#if NETWORK_DEBUG			if (bUartUp)			{				vPrintf("eJenie_Sleep() = %s\n",						aszStatusCode[eStatus]);			}		#endif	}	return eStatus;}/****************************************************************************//***        Public service functions                                      ***//****************************************************************************//**************************************************************************** * * NAME 	 	bNetwork_Service_Register *//*! *\DESCRIPTION	Add a service to be registered. * * This function adds a service to be registered in order to receive data. * and specifies how many requesting services can bind to it * * This function would normally be called from vJenie_CbConfigureNetwork() * after the call to vNetwork_ConfigureNetwork(), though it can be called to * register new services at any time. * * Services added using this function will be automatically registered by code * in the remainder of Network.c. *//* RETURNS: * None * ****************************************************************************/PUBLIC bool_t bNetwork_Service_Register (	uint8 u8Service,	/**< Service to be registered. */	uint8 u8BindLimit)	/**< Number of devices that can bind to service, (0 unlimited). */{	bool_t   bAdded = FALSE;	uint32 u32Service;	uint32 u32Mask;	/* Get mask for service to be registered */	u32Service = u32Network_Service_Mask(u8Service);	/* Get mask for registered services we don't already have in progress */	u32Mask = ~(sRegister.u32Add | sRegister.u32Pend | sRegister.u32Ready | sRegister.u32Bound);	/* Combine with service we want to register */	u32Mask &= u32Service;	/* If bind limit is 0 max it out */	if (u8BindLimit == 0) u8BindLimit = 0xFF;	/* Have we got a new service to add ? */	if (u32Mask)	{		/* Prepare to add any services we don't have already */		sRegister.u32Add |= u32Mask;		/* Set the binding limit for the service */		sRegister.au8BindLimit[u8Service-1] = u8BindLimit;		/* Registered services are not up yet */		bRegisterUp = FALSE;		/* Turn on LED prior to registering service */		vLedControl(0, TRUE);		/* Note we prepared to register the service */		bAdded = TRUE;	}	return bAdded; /**< \return TRUE when new service is added for registering */}/**************************************************************************** * * NAME 	 	bNetwork_Service_Request *//*! *\DESCRIPTION	Add a service to be requested and bound. * * This function adds a service to be requested and bound in order to transmit * data and specifies how many registered services it should attempt to bind to. * * This function would normally be called either from vJenie_CbConfigureNetwork() * after the call to vNetwork_ConfigureNetwork() in order to request services * that always need to be available or it could be called to initiate the request * process when controlling the binding process through the use of buttons. * * Services added using this function will be automatically requested and bound by code * in the remainder of Network.c. *//* RETURNS: * None * ****************************************************************************/PUBLIC bool_t bNetwork_Service_Request (	uint8 u8Service,	/**< Service to be requested. */	uint8 u8BindLimit)	/**< Number of devices that service can bind to.						 *	 Minimum bindings that will be made, (0 is changed to one).*/{	bool_t   bAdded = FALSE;	uint32 u32Service;	uint32 u32Mask;	/* Get mask for service to be requested */	u32Service = u32Network_Service_Mask(u8Service);	/* Get mask for requested services we don't already have in progress */	u32Mask = ~(sRequest.u32Add | sRequest.u32Pend | sRequest.u32Ready | sRequest.u32Bound);	/* Combine with service we want to request */	u32Mask &= u32Service;	/* If bind limit is 0 update it to one */	if (u8BindLimit == 1) u8BindLimit = 1;	/* Have we got a new service to add ? */	if (u32Mask)	{		/* Prepare to add any services we don't have already */		sRequest.u32Add |= u32Mask;		/* Set the binding limit for the service */		sRequest.au8BindLimit[u8Service-1] = u8BindLimit;		/* Requested services are not up yet */		bRequestUp = FALSE;		/* Turn on LED prior to requesting service */		vLedControl(1, TRUE);		/* Note we prepared to request the service */		bAdded = TRUE;	}	return bAdded; /**< \return TRUE when new service is added for requesting */}/**************************************************************************** * * NAME: 		eNetwork_Service_Tx *//*! *\DESCRIPTION	Transmits data over the network to a requested service. *//* RETURNS: * None * ****************************************************************************/PUBLIC teJenieStatusCode eNetwork_Service_Tx (	uint8   u8Service, 	/**< Service to transmit data to */	uint16 u16Length, 	/**< Length of data */	uint8 *pu8Data)		/**< Pointer to data */{	bool_t 			  bLive = FALSE;	teJenieStatusCode eStatus = E_JENIE_ERR_INVLD_PARAM;	uint32			 u32Service;	/* Get mask for service */	u32Service = u32Network_Service_Mask(u8Service);	/* Is this service live ? */	if (u32Service & sRequest.u32Bound)	{		/* Note we're live */		bLive = TRUE;		/* Set transmit timer - used to flash LED */		u8ServiceTxTimer = 2;		/* Send the data */		eStatus = eJenie_SendDataToBoundService(u8Service, pu8Data, u16Length, TXOPTION_ACKREQ);	}	/* Network debugging */	#if NETWORK_DEBUG		if (bUartUp)		{			if (bNetwork_IsString(u16Length, pu8Data))			{				/* Debug with data */				vPrintf("bNetwork_Service_Tx(%d, %d, \"%s\") = %d\n",								u8Service,								u16Length,								(char *) pu8Data,								bLive);				/* Sent the data ? */				if (bLive)				{					/* Debug with data */					vPrintf("eJenie_SendDataToBoundService(%d, \"%s\", %d, %x) = %s\n",									u8Service,									(char *) pu8Data,									u16Length,									TXOPTION_ACKREQ,									aszStatusCode[eStatus]);				}			}			else			{				/* Debug with data */				vPrintf("bNetwork_Service_Tx(%d, %d) = %d\n",								u8Service,								u16Length,								bLive);				/* Sent the data */				if (bLive)				{					/* Debug without data */					vPrintf("eJenie_SendDataToBoundService(%d, %d, %x) = %s\n",									u8Service,									u16Length,									TXOPTION_ACKREQ,									aszStatusCode[eStatus]);				}			}		}	#endif	return eStatus;	/**< \return Status of call to eJenie_SendDataToBoundService(). */}/**************************************************************************** * * NAME 		vNetwork_Service_Rx *//*! *\DESCRIPTION	Receivess data over the network for a registered service. *//* RETURNS: * None * ****************************************************************************/PUBLIC void vNetwork_Service_Rx	(	uint64 u64Address, 	/**< Address data received from */	uint8   u8Service, 	/**< Service to receive data */	uint16 u16Length, 	/**< Length of data */	uint8 *pu8Data)		/**< Pointer to data */{	bool_t 			  bLive = FALSE;	uint32			 u32Service;	/* Get mask for service */	u32Service = u32Network_Service_Mask(u8Service);	/* Is this service live ? */	if (u32Service & sRegister.u32Bound)	{		/* Note we're live */		bLive = TRUE;		/* Set receive timer - used to flash LED */		u8ServiceRxTimer = 2;		/* Pass data on to device module one of Coordinator.c, Router.c or EndDevice.c		 * though function is declared in Network.h */		vDevice_Service_Rx(u64Address, u8Service, u16Length, pu8Data);	}	/* Network debugging */	#if NETWORK_DEBUG		if (bUartUp)		{			if (bNetwork_IsString(u16Length, pu8Data))			{				/* Debug with data */				vPrintf("vNetwork_Service_Rx(%x:%x, %d, %d, \"%s\") = %d\n",								(uint32) (u64Address >> 32),								(uint32) (u64Address  & 0xFFFFFFFF),								u8Service,								u16Length,								(char *) pu8Data,								bLive);			}			else			{				/* Debug with data */				vPrintf("vNetwork_Service_Rx(%x:%x, %d, %d) = %d\n",								(uint32) (u64Address >> 32),								(uint32) (u64Address  & 0xFFFFFFFF),								u8Service,								u16Length,								bLive);			}		}	#endif}/**************************************************************************** * * NAME 		vNetwork_Service_Mask *//*! *\DESCRIPTION 	Calculate bitmask for a service. *//* RETURNS: * None * ****************************************************************************/PUBLIC uint32 u32Network_Service_Mask (uint8 u8Service) /**< Service to calculate bitmask for */{	uint32 u32Service = 0;	if (u8Service >= 1 && u8Service <= 32)

⌨️ 快捷键说明

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