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

📄 network.c

📁 关于zigbee厂家jennic的zigbee通信模块JN5139的一些示例程序。
💻 C
📖 第 1 页 / 共 5 页
字号:
/*!
 *\DESCRIPTION	Get maximum bindings for a destination service
 */
/* RETURNS:
 * None
 *
 ****************************************************************************/
PUBLIC uint8 u8Network_Destination_Limit (
	uint8   u8Destination)	/**< Destination service to get bind limit for. */
{
	uint8 u8Return = 0;

	/* Get limit */
	u8Return = u8Network_Service_Limit(0, u8Destination);

	return u8Return; /**! \return Current binding limit for service. */
}

/****************************************************************************
 *
 * NAME 	 	u8Network_Destination_Count
 */
/*!
 *\DESCRIPTION	Get maximum bindings for a destination service
 */
/* RETURNS:
 * None
 *
 ****************************************************************************/
PUBLIC uint8 u8Network_Destination_Count (
	uint8   u8Destination)	/**< Destination service to get bind count for. */
{
	uint8 u8Return = 0;

	/* Get count */
	u8Return = u8Network_Service_Count(0, u8Destination);

	return u8Return; /**! \return Current binding count for service. */
}

/****************************************************************************
 *
 * NAME: 		eNetwork_Source_Tx
 */
/*!
 *\DESCRIPTION	Transmits data from a source service
 */
/* RETURNS:
 * None
 *
 ****************************************************************************/
PUBLIC teJenieStatusCode eNetwork_Source_Tx (
	uint8   u8Source, 	/**< Source service to transmit data from */
	uint16 u16Length, 	/**< Length of data */
	uint8 *pu8Data)		/**< Pointer to data */
{
	bool_t 			  bLive = FALSE;
	teJenieStatusCode eStatus = E_JENIE_ERR_INVLD_PARAM;

	/* Is this a vlid requested service ? */
	if (u8Source >= 1 && u8Source <= NETWORK_MAX_SOURCE)
	{
		/* Has this service got some bindings and the network is up ? */
		if (asServices[u8Source].u32Ready != 0 && bNetworkUp == TRUE)
		{
			/* Note we're live */
			bLive = TRUE;
			/* Send the data */
			eStatus = eJenie_SendDataToBoundService(u8Source, pu8Data, u16Length, NETWORK_TXOPTION);
			#if NETWORK_LED
			/* Pulse LED 1 */
			if (u8Source == 1) u8Led1Timer = LED_PULSE;
			#endif
		}
	}

	/* Network debugging */
	#if NETWORK_DEBUG
		if (bUartUp)
		{
			if (bNetwork_IsString(u16Length, pu8Data))
			{
				/* Debug with data */
				vPrintf("bNetwork_Source_Tx(%d, %d, \"%s\") = %d\n",
								u8Source,
								u16Length,
								(char *) pu8Data,
								bLive);
				/* Sent the data ? */
				if (bLive)
				{
					/* Debug with data */
					vPrintf("eJenie_SendDataToBoundService(%d, \"%s\", %d, %x) = %s\n",
									u8Source,
									(char *) pu8Data,
									u16Length,
									NETWORK_TXOPTION,
									aszStatusCode[eStatus]);
				}
			}
			else
			{
				/* Debug with data */
				vPrintf("bNetwork_Source_Tx(%d, %d) = %d\n",
								u8Source,
								u16Length,
								bLive);
				/* Sent the data */
				if (bLive)
				{
					/* Debug without data */
					vPrintf("eJenie_SendDataToBoundService(%d, %d, %x) = %s\n",
									u8Source,
									u16Length,
									NETWORK_TXOPTION,
									aszStatusCode[eStatus]);
				}
			}
		}
	#endif

	return eStatus;	/**< \return Status of call to eJenie_SendDataToBoundService(). */
}

/****************************************************************************
 *
 * NAME 		vNetwork_Destination_Rx
 */
/*!
 *\DESCRIPTION	Receives data over the network for a destination service.
 */
/* RETURNS:
 * None
 *
 ****************************************************************************/
PUBLIC void vNetwork_Destination_Rx	(
	uint64 u64Address, 	    /**< Address data received from */
	uint8   u8Destination, 	/**< Destination service to receive data */
	uint16 u16Length, 	    /**< Length of data */
	uint8 *pu8Data)		    /**< Pointer to data */
{

	/* Correct service ? */
	if (u8Destination == 1)
	{
		/* Pass the data on to the protocol */
		vProtocol_Rx(u16Length, pu8Data);
	}

	#if NETWORK_LED
	/* Pulse LED 0 */
	if (u8Destination == 1) u8Led0Timer = LED_PULSE;
	#endif

	/* Network debugging */
	#if NETWORK_DEBUG
		if (bUartUp)
		{
			if (bNetwork_IsString(u16Length, pu8Data))
			{
				/* Debug with data */
				vPrintf("vNetwork_Service_Rx(%x:%x, %d, %d, \"%s\")\n",
								(uint32) (u64Address >> 32),
								(uint32) (u64Address  & 0xFFFFFFFF),
								u8Destination,
								u16Length,
								(char *) pu8Data);
			}
			else
			{
				/* Debug with data */
				vPrintf("vNetwork_Service_Rx(%x:%x, %d, %d)\n",
								(uint32) (u64Address >> 32),
								(uint32) (u64Address  & 0xFFFFFFFF),
								u8Destination,
								u16Length);
			}
		}
	#endif
}

/****************************************************************************
 *
 * NAME: vNetwork_BinToHex
 */
/*!
 *\DESCRIPTION Converts binary value to ascii hex (does not add null terminator)
 */
/* RETURNS:
 * None
 *
 ****************************************************************************/
PUBLIC void vNetwork_BinToHex (
	uint8 *pu8Hex,
	uint32 u32Bin,
	uint8   u8Digits)
{
	uint8 u8Digit;
	uint8 u8Shift;

	/* Valid hex pointer ? */
	if (pu8Hex != NULL)
	{
		/* Loop through digits */
		for (u8Digit = 0, 		u8Shift = (u8Digits-1) * 4;
			 u8Digit < u8Digits;
			 u8Digit++, 		u8Shift -= 4)
		{
			/* Convert digit */
			pu8Hex[u8Digit] = szAsciiHex[(u32Bin >> u8Shift) & 0x0F];
		}
	}
}

/****************************************************************************
 *
 * NAME: u32Network_HexToBin
 */
/*!
 *\DESCRIPTION Converts ascii hex value to binary
 */
/* RETURNS:
 * None
 *
 ****************************************************************************/
PUBLIC uint32 u32Network_HexToBin (
	uint8 *pu8Hex,
	uint8   u8Digits)
{
	uint32 u32Bin = 0;
	uint8 u8Digit;

	/* Valid hex pointer ? */
	if (pu8Hex != NULL)
	{
		/* Loop through digits */
		for (u8Digit = 0;
			 u8Digit < u8Digits;
			 u8Digit++)
		{
			/* Shift data */
			u32Bin = u32Bin << 4;
			/* Convert digit */
			if      (pu8Hex[u8Digit] >= '0' && pu8Hex[u8Digit] <= '9') u32Bin += (pu8Hex[u8Digit] - '0');
			else if (pu8Hex[u8Digit] >= 'A' && pu8Hex[u8Digit] <= 'F') u32Bin += (pu8Hex[u8Digit] + 0x0A - 'A');
		}
	}

	return u32Bin;
}

/****************************************************************************/
/***        Private service functions                                     ***/
/****************************************************************************/

/****************************************************************************
 *
 * NAME 	 	eNetwork_Services_Enabled
 */
/*!
 *\DESCRIPTION	Set bindings enabled for services
 */
/* RETURNS:
 * None
 *
 ****************************************************************************/
PRIVATE teJenieStatusCode eNetwork_Services_Enabled (
	uint8   u8Source,		/**< Source service to set bind enable for. */
	uint32 u32Destinations,	/**< Destination services to set bind enable for. */
	bool_t   bEnabled)		/**< Enabled binding for service */
{
	teJenieStatusCode eReturn = E_JENIE_ERR_INVLD_PARAM;

	/* Valid source and destinations ? */
	if (u8Source        <= NETWORK_MAX_SOURCE &&
		u32Destinations != 0)
	{
		/* Enabling destination services ? */
		if (bEnabled == TRUE)
		{
			/* Enabled services */
			asServices[u8Source].u32Enabled |= u32Destinations;
		}
		/* Disabling destination services ? */
		else
		{
			/* Disable services */
			asServices[u8Source].u32Enabled &= ~u32Destinations;
		}
		/* Update allowed flags for this service */
		eNetwork_Service_Allow(u8Source);
		/* Set return value */
		eReturn = E_JENIE_SUCCESS;
	}

	return eReturn; /**! \return E_JENIE_SUCCESS when service is updated */
}

/****************************************************************************
 *
 * NAME 	 	bNetwork_Service_Enabled
 */
/*!
 *\DESCRIPTION	Get binding enable for a service
 */
/* RETURNS:
 * None
 *
 ****************************************************************************/
PRIVATE bool_t bNetwork_Service_Enabled (
	uint8   u8Source,		/**< Source service to get bind limit for. */
	uint8   u8Destination)	/**< Destination service to get bind limit for. */
{
	bool_t bReturn = FALSE;

	/* Valid source ? */
	if (u8Source <= NETWORK_MAX_SOURCE)
	{
		/* Is binding enabled for service ? */
		if (asServices[u8Source].u32Enabled & u32Network_Service_Mask(u8Destination))
		{
			/* Note service binding is enabled */
			bReturn = TRUE;
		}
	}

	return bReturn; /**! \return Binding enabled for service. */
}

/****************************************************************************
 *
 * NAME 	 	eNetwork_Services_Limit
 */
/*!
 *\DESCRIPTION	Set maximum bindings for services
 */
/* RETURNS:
 * None
 *
 ****************************************************************************/
PRIVATE teJenieStatusCode eNetwork_Services_Limit (
	uint8   u8Source,		/**< Source service to set bind limit for. */
	uint32 u32Destinations,	/**< Destination services to set bind limit for. */
	uint8   u8Limit)		/**< Maximum bindings for service */
{
	teJenieStatusCode eReturn = E_JENIE_ERR_INVLD_PARAM;
	uint8   u8Destination;
	uint32 u32Destination;
	uint32 u32Done = 0;

	/* Valid source and destinations ? */
	if (u8Source        <= NETWORK_MAX_SOURCE &&
		u32Destinations != 0)
	{
		/* Loop though all possible destination services */
		for (u8Destination  = 1;
			 u8Destination <= 32 && u32Done != u32Destinations;
			 u8Destination++)
		{
			/* Get mask for this possible destination service */
			u32Destination = u32Network_Service_Mask(u8Destination);
			/* Is this service one of the destination services ? */
			if ((u32Destination & u32Destinations) != 0)
			{
				/* Update the limit for the individual service */
				(void) eNetwork_Service_Limit(u8Source, u8Destination, u8Limit);
				/* We have done this destination service */
				u32Done |= u32Destination;
			}
		}
		/* Set return value */
		eReturn = E_JENIE_SUCCESS;
	}

	return eReturn; /**! \return E_JENIE_SUCCESS when valid services specified. */
}

/****************************************************************************
 *
 * NAME 	 	eNetwork_Service_Limit
 */
/*!
 *\DESCRIPTION	Set maximum bindings for a service
 */
/* RETURNS:
 * None
 *
 ****************************************************************************/
PRIVATE teJenieStatusCode eNetwork_Service_Limit (
	uint8   u8Source,		/**< Source service to set bind limit for. */
	uint8   u8Destination,	/**< Destination service to set bind limit for. */
	uint8   u8Limit)		/**< Maximum bindings for service */
{
	teJenieStatusCode eReturn = E_JENIE_ERR_INVLD_PARAM;

	/* Valid source and destinations ? */
	if (u8Source      <= NETWORK_MAX_SOURCE &&
		u8Destination >= 1 && u8Destination <= 32)
	{
		/* Is the current limit different to the specified limit ? */
		if (asServices[u8Source].au8Limit[u8Destination-1] != u8Limit)
		{
			/* Note the new limit */
			asServices[u8Source].au8Limit[u8Destination-1] = u8Limit;
			/* Update the free flag for this service */
			eNetwork_Service_Free(u8Source, u8Destination);
		}
		/* Set return value */
		eReturn = E_JENIE_SUCCESS;
	}

	return eReturn; /**! \return E_JENIE_SUCCESS when valid service is specified. */
}

/****************************************************************************
 *
 * NAME 	 	u8Network_Service_Limit
 */
/*!
 *\DESCRIPTION	Get maximum bindings for a service
 */
/* RETURNS:
 * None
 *
 ****************************************************************************/
PRIVATE uint8 u8Network_Service_Limit (
	uint8   u8Source,		/**< Source service to get bind limit for. */
	uint8   u8Destination)	/**< Destination service to get bind limit for. */
{
	uint8 u8Return = 0;

	/* Valid source and destinations ? */
	if (u8Source      <= NETWORK_MAX_SOURCE &&
		u8Destination >= 1 && 

⌨️ 快捷键说明

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