📄 network.c
字号:
/**************************************************************************** * * NAME vNetwork_StackMgmtEvent *//*! *\DESCRIPTION Called when stack management event has occurred. * * This function should be called from vJenie_CbStackMgmtEvent() as it performs * the network management tasks common to all Jenie device types. *//* RETURNS * None * ****************************************************************************/PUBLIC void vNetwork_StackMgmtEvent ( teEventType eEventType, /**< Type of stack management event received */ void *pvEventPrim) /**< Pointer to event primitive */{ teJenieStatusCode eStatus; uint8 u8Service; uint32 u32Service; /* Which event has occurred ? */ switch (eEventType) { /* Register Service Response ? */ case E_JENIE_REG_SVC_RSP: { /* Empty primitive structure for this event */ ; /* Network debugging */ #if NETWORK_DEBUG if (bUartUp) { vPrintf("vNetwork_StackMgmtEvent(%s)\n", aszEventType[eEventType]); } #endif /* Are we waiting for a register response ? */ if (eServiceState == E_SERVICE_STATE_REGISTER) { /* Note the services we registered */ sRegister.u32Ready |= sRegister.u32Pend; sRegister.u32Pend = 0; /* Return to idle state */ vNetwork_Service_State(E_SERVICE_STATE_IDLE); } } break; /* Request Service Response ? */ case E_JENIE_SVC_REQ_RSP: { /* Get pointer to correct primitive structure */ tsSvcReqRsp *psSvcReqRsp = (tsSvcReqRsp *) pvEventPrim; /* Network debugging */ #if NETWORK_DEBUG if (bUartUp) { vPrintf("vNetwork_StackMgmtEvent(%s, %x:%x, %x)\n", aszEventType[eEventType], (uint32) (psSvcReqRsp->u64SrcAddress >> 32), (uint32) (psSvcReqRsp->u64SrcAddress & 0xFFFFFFFF), psSvcReqRsp->u32Services); } #endif /* Are we waiting for a request response ? */ if (eServiceState == E_SERVICE_STATE_REQUEST) { /* Loop through individual services */ for (u8Service = 1; u8Service <= 32; u8Service++) { /* Get mask for service */ u32Service = u32Network_Service_Mask(u8Service); /* Is this service supported ? */ if (psSvcReqRsp->u32Services & u32Service) { /* Send bind query for service */ (void) eNetwork_Service_BindTx('q', u8Service, psSvcReqRsp->u64SrcAddress); } } /* No more requested services pending ? */ if (sRequest.u32Pend == 0) { /* Return to idle state */ vNetwork_Service_State(E_SERVICE_STATE_IDLE); } } } break; /* Poll complete ? */ case E_JENIE_POLL_CMPLT: /* Don't do any debugging - too many of these */ ; break; /* Network up ? */ case E_JENIE_NETWORK_UP: { /* Network debugging */ #if NETWORK_DEBUG if (bUartUp) { /* Get pointer to correct primitive structure */ tsNwkStartUp *psNwkStartUp = (tsNwkStartUp *) pvEventPrim; vPrintf("vNetwork_StackMgmtEvent(%s, %x:%x)\n", aszEventType[eEventType], (uint32) (psNwkStartUp->u64ParentAddress >> 32), (uint32) (psNwkStartUp->u64ParentAddress & 0xFFFFFFFF)); } #endif /* Note network is now up */ bNetworkUp = TRUE; /* End device or we have all the children we want ? */ if (eDeviceType == E_JENIE_END_DEVICE || u8Children >= u8MaxChildren ) { /* 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 } 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; /* Child joined ? */ case E_JENIE_CHILD_JOINED: { /* Network debugging */ #if NETWORK_DEBUG if (bUartUp) { /* Get pointer to correct primitive structure */ tsChildJoined *psChildJoined = (tsChildJoined *) pvEventPrim; vPrintf("vNetwork_StackMgmtEvent(%s, %x:%x)\n", aszEventType[eEventType], (uint32) (psChildJoined->u64SrcAddress >> 32), (uint32) (psChildJoined->u64SrcAddress & 0xFFFFFFFF)); } #endif /* Update number of children */ u8Children++; /* Got all the children we want ? */ if (u8Children >= u8MaxChildren ) { /* 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 to service ? */ case E_JENIE_DATA_TO_SERVICE: { /* Get pointer to correct primitive structure */ tsDataToService *psDataToService = (tsDataToService *) pvEventPrim; /* Network debugging */ #if NETWORK_DEBUG if (bUartUp) { /* Data is a string ? */ if (bNetwork_IsString(psDataToService->u16Length, psDataToService->pau8Data)) { /* Debug with data string */ vPrintf("vNetwork_StackDataEvent(%s, %x:%x, %d, %d, %x, %d, \"%s\")\n", aszEventType[eEventType], (uint32) (psDataToService->u64SrcAddress >> 32), (uint32) (psDataToService->u64SrcAddress & 0xFFFFFFFF), psDataToService->u8SrcService, psDataToService->u8DestService, psDataToService->u8MsgFlags, psDataToService->u16Length, (char *) psDataToService->pau8Data); } else { /* Debug without data */ vPrintf("vNetwork_StackDataEvent(%s, %x:%x, %d, %d, %x, %d)\n", aszEventType[eEventType], (uint32) (psDataToService->u64SrcAddress >> 32), (uint32) (psDataToService->u64SrcAddress & 0xFFFFFFFF), psDataToService->u8SrcService, psDataToService->u8DestService, psDataToService->u8MsgFlags, psDataToService->u16Length); } } #endif /* Receive the data */ vNetwork_Service_Rx(psDataToService->u64SrcAddress, psDataToService->u8SrcService, psDataToService->u16Length, psDataToService->pau8Data); } break; /* 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(); } /* Timer running ? */ if (u8ServiceStateTimer > 0) { /* Decrement timer */ u8ServiceStateTimer--; /* Timer expired ? */ if (u8ServiceStateTimer == 0) { /* Handle the timeout */ vNetwork_Service_Timeout(); } } /* Receive LED timer running ? */ if (u8ServiceRxTimer > 0) { u8ServiceRxTimer--; /* Expired - turn out LED */ if (u8ServiceRxTimer == 0 && bRegisterUp) vLedControl(0, FALSE); /* Running - turn on */ else vLedControl(0, TRUE); } /* Transmit LED timer running ? */ if (u8ServiceTxTimer > 0) { u8ServiceTxTimer--; /* Expired - turn out LED */ if (u8ServiceTxTimer == 0 && bRequestUp) vLedControl(1, FALSE); /* Running - turn on */ else vLedControl(1, TRUE); } /* 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -