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

📄 network.c

📁 Application note Jennic wifi modules sensor wireless
💻 C
📖 第 1 页 / 共 2 页
字号:
				/* Network debugging */				#if NETWORK_DEBUG					if (bUartUp)					{						vPrintf("eJenie_SetPermitJoin(FALSE) = %s\n",								aszStatusCode[eStatus]);					}				#endif			}			else			{				/* Allow devices to join to us */				eStatus = eJenie_SetPermitJoin(TRUE);				/* Network debugging */				#if NETWORK_DEBUG					if (bUartUp)					{						vPrintf("eJenie_SetPermitJoin(TRUE) = %s\n",							aszStatusCode[eStatus]);					}				#endif			}		}		break;	/* Stack reset (network down) ? */	case E_JENIE_STACK_RESET:		{			/* Network debugging */			#if NETWORK_DEBUG				if (bUartUp)				{					vPrintf("vNetwork_StackMgmtEvent(%s)\n",						aszEventType[eEventType]);				}			#endif			/* Note network is now down */			bNetworkUp = FALSE;			/* Update LED */			vLedControl(1,bNetworkUp);			/* Don't allow devices to join to us */			eStatus = eJenie_SetPermitJoin(FALSE);			/* Network debugging */			#if NETWORK_DEBUG				if (bUartUp)				{					vPrintf("eJenie_SetPermitJoin(FALSE) = %s\n",							aszStatusCode[eStatus]);				}			#endif		}		break;	/* Others ? */	default:		{			/* Network debugging */			#if NETWORK_DEBUG				if (bUartUp)				{					vPrintf("vNetwork_StackMgmtEvent(%s)\n",                	    	aszEventType[eEventType]);                }			#endif		}		break;	}}/**************************************************************************** * * NAME 		vNetwork_StackDataEvent *//*! *\DESCRIPTION	Called when data event has occurred. * * This function should be called from vJenie_CbStackDataEvent() as it passes * the received data onto vNetwork_Service_Rx() for data sent to a registered service * and vNetwork_Rx() for addressed directly to the device. *//* RETURNS * None * ****************************************************************************/PUBLIC void vNetwork_StackDataEvent (	teEventType   eEventType,	/**< Type of data event received */    void        *pvEventPrim)	/**< Pointer to event primitive */{	/* Which event has occurred ? */	switch (eEventType)	{	/* Data ? */	case E_JENIE_DATA:		{			/* Get pointer to correct primitive structure */			tsData *psData = (tsData *) pvEventPrim;			/* Network debugging */			#if NETWORK_DEBUG				if (bUartUp)				{					/* Data is a string ? */					if (bNetwork_IsString(psData->u16Length, psData->pau8Data))					{						/* Debug with data string */						vPrintf("vNetwork_StackDataEvent(%s, %x:%x, %x, %d, \"%s\")\n",							aszEventType[eEventType],							(uint32) (psData->u64SrcAddress >> 32),							(uint32) (psData->u64SrcAddress  & 0xFFFFFFFF),							psData->u8MsgFlags,							psData->u16Length,							(char *) psData->pau8Data);					}					else					{						/* Debug without data */						vPrintf("vNetwork_StackDataEvent(%s, %x:%x, %x, %d)\n",							aszEventType[eEventType],							(uint32) (psData->u64SrcAddress >> 32),							(uint32) (psData->u64SrcAddress  & 0xFFFFFFFF),							psData->u8MsgFlags,							psData->u16Length);					}				}			#endif			/* Receive the data */			vNetwork_Rx(psData->u64SrcAddress,					    psData->u16Length,						psData->pau8Data);			}		break;	/* Others ? */	default:		/* Network debugging */		#if NETWORK_DEBUG			if (bUartUp)			{				vPrintf("vNetwork_StackDataEvent(%s)\n", aszEventType[eEventType]);			}		#endif		break;	}}/**************************************************************************** * * NAME 		vNetwork_HwEvent *//*! *\DESCRIPTION	Called when a stack hardware event has occurred. * * This function should be called from vJenie_HwEvent() as it performs * the network management tasks common to all Jenie device types. *//* RETURNS * None * ****************************************************************************/PUBLIC void vNetwork_HwEvent (	uint32 u32DeviceId,		/**< Device that generated the event. */ 	uint32 u32ItemBitmap)	/**< Source within device that generated the event. */{	teJenieStatusCode eStatus;	/* Wake timer 1 event ? */	if (u32DeviceId  == E_JPI_DEVICE_SYSCTRL &&	   (u32ItemBitmap & E_JPI_SYSCTRL_WK1_MASK) != 0)	{		/* End Device and network is up ? */		if (eDeviceType == E_JENIE_END_DEVICE && bNetworkUp)		{			/* Poll parent for data */			eStatus = eJenie_PollParent();		}		/* Update the sensor timer */		vSensor_Tick();		/* Run the timer for another 100ms */		vJPI_WakeTimerStart(E_JPI_WAKE_TIMER_1, 3200);	}}/**************************************************************************** * * NAME 		vNetwork_Tx *//*! *\DESCRIPTION	Transmits data over the network - independent of a service. * * Transmits data over the network to a specified address, no service is * used. * * This function is used to implement to binding permission protocol. * * This function simply adds debugging of the call to eJenie_SendData(). *//* RETURNS * None * ****************************************************************************/PUBLIC teJenieStatusCode eNetwork_Tx (	uint64 u64Address, 	/**< Address to transmit data to */	uint16 u16Length,  	/**< Length of data */	uint8 *pu8Data)		/**< Pointer to data */{	teJenieStatusCode  eStatus;	/* 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	/* Pass remote reading to sensor module for handling */	vSensor_Remote(u64Address, u16Length, pu8Data);}/**************************************************************************** * * NAME	 		eNetwork_Sleep *//*! *\DESCRIPTION	Go to sleep. *//* RETURNS: * None * ****************************************************************************/PUBLIC teJenieStatusCode eNetwork_Sleep	(	uint32 				u32SleepPeriodMs, 	/**< Length of time to sleep for (ms) */	teJenieSleepMode 	  eSleepMode)		/**< Sleep mode */{	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(eSleepMode);		/* Network debugging */		#if NETWORK_DEBUG			if (bUartUp)			{				vPrintf("eJenie_Sleep(%d) = %s\n",						eSleepMode,						aszStatusCode[eStatus]);			}		#endif	}	return eStatus;}/****************************************************************************//***        Public data access functions                                  ***//****************************************************************************/PUBLIC bool_t 			 bNetwork_Up 		 (void) { return  bNetworkUp;  }PUBLIC bool_t 			 bNetwork_UartUp 	 (void) { return  bUartUp; }PUBLIC teJenieDeviceType eNetwork_DeviceType (void) { return  eDeviceType; }/****************************************************************************//***        Private functions 			                                  ***//****************************************************************************//**************************************************************************** * * 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 + -