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

📄 network.c

📁 通过5120芯片实现无线键盘进行数据的传输功能
💻 C
📖 第 1 页 / 共 4 页
字号:
	{		u32Service = ((uint32) 1 << (u8Service - 1));	}	return u32Service;	/**< \return Bitmask for service. */}/**************************************************************************** * * NAME 		bNetwork_Service_RegisterUp *//*! *\DESCRIPTION 	Checks whether a registered service is up and running. *//* RETURNS: * None * ****************************************************************************/PUBLIC bool_t   bNetwork_Service_RegisterUp (uint8 u8Service){	return (sRegister.u32Bound & u32Network_Service_Mask(u8Service) ? TRUE : FALSE);}/**************************************************************************** * * NAME 		bNetwork_Service_RequestUp *//*! *\DESCRIPTION 	Checks whether a requested service is up and running. *//* RETURNS * None * ****************************************************************************/PUBLIC bool_t   bNetwork_Service_RequestUp (uint8 u8Service){	return (sRequest.u32Bound & u32Network_Service_Mask(u8Service) ? TRUE : FALSE);}/****************************************************************************//***        Public data access functions                                  ***//****************************************************************************/PUBLIC bool_t 	bNetwork_Up 		 		 (void) { return  bNetworkUp;  }PUBLIC bool_t 	bNetwork_Services_Up 		 (void) { return (bRegisterUp & bRequestUp); }PUBLIC bool_t 	bNetwork_Services_RegisterUp (void) { return  bRegisterUp; }PUBLIC bool_t 	bNetwork_Services_RequestUp  (void) { return  bRequestUp; }PUBLIC bool_t 	bNetwork_UartUp 			 (void) { return  bUartUp; }PUBLIC teJenieDeviceType eNetwork_DeviceType (void) { return  eDeviceType; }/****************************************************************************//***        Private service functions                                     ***//****************************************************************************//**************************************************************************** * * NAME 		vNetwork_Service_State *//*! *\DESCRIPTION  Update service state machine and timer. *//* RETURNS: * None * ****************************************************************************/PRIVATE void vNetwork_Service_State (teServiceState eState){	/* Service state changed ? */	if (eServiceState != eState)	{		/* Note the new service state */		eServiceState = eState;		/* Set the service state timer */		u8ServiceStateTimer = au8ServiceStateTimeout[eServiceState];		/* Network debugging */		#if NETWORK_DEBUG			if (bUartUp)			{				vPrintf("vNetwork_Service_State(%s)\n",						aszServiceState[eServiceState]);			}		#endif	}}/**************************************************************************** * * NAME: vNetwork_Service_Timeout *//*! *\DESCRIPTION Handle a service state timeout. *//* RETURNS: * None * ****************************************************************************/PRIVATE void vNetwork_Service_Timeout (void){	/* Network debugging */	#if NETWORK_DEBUG		if (bUartUp)		{			vPrintf("vNetwork_Service_Timeout(%s)\n",				aszServiceState[eServiceState]);		}	#endif	/* Are we waiting for a register response ? */	if (eServiceState == E_SERVICE_STATE_REGISTER)	{		/* Try to register the pending service again */		sRegister.u32Add |= sRegister.u32Pend;		sRegister.u32Pend  = 0;	}	/* Are we waiting for a request response ? */	else if (eServiceState == E_SERVICE_STATE_REQUEST)	{		/* Try to register the pending service again */		sRequest.u32Add  |= sRequest.u32Pend;		sRequest.u32Pend  = 0;	}	/* Return to idle state */	vNetwork_Service_State(E_SERVICE_STATE_IDLE);}/**************************************************************************** * * NAME: vNetwork_Services_RegisterStart *//*! *\DESCRIPTION Starts registering services waiting to be added. *//* RETURNS: * None * ****************************************************************************/PRIVATE void vNetwork_Services_RegisterStart (void){	teJenieStatusCode eStatus;	/* Check we are idle and have services to register */	if (eServiceState    == E_SERVICE_STATE_IDLE &&		sRegister.u32Add != 0)	{		/* Note the services we are going to try to register */		sRegister.u32Pend = sRegister.u32Add;		sRegister.u32Add  = 0;		/* Attempt to register services */		eStatus = eJenie_RegisterServices(sRegister.u32Pend);		/* Network debugging */		#if NETWORK_DEBUG			if (bUartUp)			{				vPrintf("eJenie_RegisterServices(%x) = %s\n",						sRegister.u32Pend,						aszStatusCode[eStatus]);			}		#endif		/* Success ? */		if (eStatus == E_JENIE_SUCCESS)		{			/* Note the services we registered */			sRegister.u32Ready |= sRegister.u32Pend;			sRegister.u32Pend  = 0;		}		else		{			/* Wait for register service response next */			vNetwork_Service_State(E_SERVICE_STATE_REGISTER);		}	}}/**************************************************************************** * * NAME: vNetwork_Services_RequestStart *//*! *\DESCRIPTION Starts requesting services waiting to be added. *//* RETURNS: * None * ****************************************************************************/PRIVATE void vNetwork_Services_RequestStart (void){	teJenieStatusCode 	  eStatus;	/* Check we are idle and have services to request */	if (eServiceState    == E_SERVICE_STATE_IDLE &&		sRequest.u32Add != 0)	{		/* Note the services we are going to try to request */		sRequest.u32Pend  = sRequest.u32Add;		sRequest.u32Add   = 0;		/* Attempt to request services */		eStatus = eJenie_RequestServices(sRequest.u32Pend, FALSE);		/* Network debugging */		#if NETWORK_DEBUG			if (bUartUp)			{				vPrintf("eJenie_RequestServices(%x) = %s\n",						sRequest.u32Pend,						aszStatusCode[eStatus]);			}		#endif		/* Wait for request service response next */		vNetwork_Service_State(E_SERVICE_STATE_REQUEST);	}}/**************************************************************************** * * NAME: vNetwork_Service_BindTx *//*! *\DESCRIPTION Transmits a binding protocol message over the network. *//* RETURNS: * None * ****************************************************************************/PRIVATE teJenieStatusCode eNetwork_Service_BindTx (char cType, uint8 u8Service, uint64 u64Address){	teJenieStatusCode  eStatus = E_JENIE_ERR_INVLD_PARAM;	/* Valid service ? */	if (u8Service >= 1 && u8Service <= 32)	{		/* Create bind message */		char aszBind[7] = "<B_00>";		/* Place command type into message */		aszBind[2] = cType;		/* Place service number into bind message */		aszBind[3] += u8Service/10;		aszBind[4] += u8Service%10;		/* Transmit bind message */		eStatus = eNetwork_Tx (u64Address, 7, (uint8 *) aszBind);	}	return eStatus;}/**************************************************************************** * * NAME: vNetwork_Service_BindRx *//*! *\DESCRIPTION Receives a binding protocol message from the network. *//* RETURNS: * None * ****************************************************************************/PRIVATE void vNetwork_Service_BindRx	(uint64 u64Address, uint16 u16Length, uint8 *pu8Data){	uint8 	u8Service;	uint32 u32Service;	/* Does this look like an binding protocol message ? */	if (pu8Data[0] == '<' && pu8Data[1] == 'B')	{		/* Extract service from message */		u8Service  = (pu8Data[3] - '0') * 10;		u8Service += (pu8Data[4] - '0');		/* Get service mask */		u32Service = u32Network_Service_Mask(u8Service);		/* Sensible service specified ? */		if (u32Service != 0)		{			/* What is the message type ? */			switch (pu8Data[2])			{				/* Query - asking permission to bind ? */				case 'q':					{						/* Is this service setup to receive data and						   we've not reached the number of bindings limit ? */						if ((u32Service & sRegister.u32Ready) != 0 &&							 sRegister.au8BindCount[u8Service-1] < sRegister.au8BindLimit[u8Service-1])						{							/* Send the response allow the binding request */							eNetwork_Service_BindTx('y', u8Service, u64Address);						}					}					break;				/* Bound - being told we've been bound to ? */				case 'b':					{						/* Increment binding counter */						sRegister.au8BindCount[u8Service-1]++;						/* Note the service that has been bound */						sRegister.u32Bound |= u32Service;					}					break;				/* Accept - granted permission to bind ? */				case 'y':					{						/* Attempt to bind to the service */						(void) eNetwork_Service_Bind(u8Service, u64Address);					}					break;				/* Others */				default:					break;			}		}	}}/**************************************************************************** * * NAME eNetwork_Service_Bind *//*! *\DESCRIPTION Binds a requested service. *//* RETURNS * None * ****************************************************************************/PRIVATE teJenieStatusCode eNetwork_Service_Bind (uint8 u8Service, uint64 u64Address){	teJenieStatusCode  eStatus = E_JENIE_ERR_INVLD_PARAM;	uint32 			 u32Service;	/* Get mask for service */	u32Service = u32Network_Service_Mask(u8Service);	/* Trying to bind to a service we requested and	   we've not yet reached the bind limit ? */	if ((sRequest.u32Pend & u32Service) != 0 &&		sRequest.au8BindCount[u8Service-1] < sRequest.au8BindLimit[u8Service-1])	{		/* Attempt to bind to the service */		eStatus = eJenie_BindService(u8Service,									 u64Address,									 u8Service);		/* Network debugging */		#if NETWORK_DEBUG			if (bUartUp)			{				vPrintf("eJenie_BindService(%d, %x:%x, %d) = %s\n",						u8Service,						(uint32) (u64Address >> 32),						(uint32) (u64Address  & 0xFFFFFFFF),						u8Service,						aszStatusCode[eStatus]);			}		#endif		/* Bind successful ? */		if (eStatus == E_JENIE_SUCCESS)		{			/* Increment the bind count */			sRequest.au8BindCount[u8Service-1]++;			/* Note the service we bound */			sRequest.u32Ready |=  u32Service;			sRequest.u32Bound |=  u32Service;			/* Have we reached the bind limit ? */			if (sRequest.au8BindCount[u8Service-1] == sRequest.au8BindLimit[u8Service-1])			{				/* Clear the pending flag - we can stop requesting that service now */				sRequest.u32Pend &= (~u32Service);				/* Go back to being idle */				vNetwork_Service_State(E_SERVICE_STATE_IDLE);			}			/* Send bound message for service */			(void) eNetwork_Service_BindTx('b', u8Service, u64Address);		}	}	return eStatus;}/**************************************************************************** * * NAME: bNetwork_IsString(u16Length, pu8Data); *//*! *\DESCRIPTION Checks if a data array can be treated as a string for debugging. *//* RETURNS: * None * ****************************************************************************/#if NETWORK_DEBUGPRIVATE bool_t bNetwork_IsString(uint16 u16Len, uint8 *pu8Data){	bool_t   bReturn = TRUE;	uint16 u16Pos;	for (u16Pos = 0; u16Pos < u16Len && bReturn == TRUE; u16Pos++)	{		/* Terminator - stop the loop */		if (pu8Data[u16Pos] == '\0') break;		/* Not printable - not a string */		else if (pu8Data[u16Pos] < ' ' || pu8Data[u16Pos] > '~') bReturn=FALSE;	}	return bReturn;}#endif/****************************************************************************//***        END OF FILE                                                   ***//****************************************************************************/

⌨️ 快捷键说明

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