teUtilsStatus eUtils_LockTryLock(tsUtilsLock *psLock) { tsLockPrivate *psLockPrivate = (tsLockPrivate *)psLock->pvPriv; #ifndef WIN32 DBG_vPrintf(DBG_LOCKS, "Thread 0x%lx try locking: %p\n", pthread_self(), psLock); if (pthread_mutex_trylock(&psLockPrivate->mMutex) != 0) { DBG_vPrintf(DBG_LOCKS, "Thread 0x%lx could not lock: %p\n", pthread_self(), psLock); return E_UTILS_ERROR_FAILED; } DBG_vPrintf(DBG_LOCKS, "Thread 0x%lx locked: %p\n", pthread_self(), psLock); #else // Wait with 0mS timeout switch(WaitForSingleObject(psLockPrivate->hMutex, 0)) { case (WAIT_OBJECT_0): DBG_vPrintf(DBG_LOCKS, "Try lock - locked\n"); return E_UTILS_OK; break; default: // Including timeout DBG_vPrintf(DBG_LOCKS, "Try lock - failed to get lock\n"); return E_UTILS_ERROR_FAILED; break; } #endif /* WIN32 */ return E_UTILS_OK; }
teUtilsStatus eUtils_LockLockImpl(tsUtilsLock *psLock, const char *pcLocation) { tsLockPrivate *psLockPrivate = (tsLockPrivate *)psLock->pvPriv; #ifndef WIN32 int err; DBG_vPrintf(DBG_LOCKS, "Thread 0x%lx locking: %p at %s\n", pthread_self(), psLock, pcLocation); if ((err = pthread_mutex_lock(&psLockPrivate->mMutex))) { DBG_vPrintf(DBG_LOCKS, "Could not lock mutex (%s)\n", strerror(err)); } else { DBG_vPrintf(DBG_LOCKS, "Thread 0x%lx locked: %p at %s\n", pthread_self(), psLock, pcLocation); #if DBG_LOCKS psLockPrivate->pcLastLockLocation = pcLocation; #endif /* DBG_LOCKS */ } #else DBG_vPrintf(DBG_LOCKS, "Locking %p at %s\n", psLock, pcLocation); WaitForSingleObject(psLockPrivate->hMutex, INFINITE); DBG_vPrintf(DBG_LOCKS, "Locked %p at %s\n", psLock, pcLocation); #endif /* WIN32 */ return E_UTILS_OK; }
/**************************************************************************** * * NAME: MibGroup_vSecond * * DESCRIPTION: * Timing function * ****************************************************************************/ PUBLIC void MibGroup_vSecond(void) { /* Need to save record ? */ if (psMibGroup->bSaveRecord) { /* Clear flag */ psMibGroup->bSaveRecord = FALSE; /* Make sure permament data is saved */ PDM_vSaveRecord(&psMibGroup->sDesc); /* Debug */ DBG_vPrintf(CONFIG_DBG_MIB_GROUP, "\nMibGroup_vSecond()"); DBG_vPrintf(CONFIG_DBG_MIB_GROUP, "\n\tPDM_vSaveRecord(MibGroup)"); #if CONFIG_DBG_MIB_GROUP { uint8 u8Group; /* Loop through current groups */ for (u8Group = 0; u8Group < MIB_GROUP_MAX; u8Group++) { /* Debug */ DBG_vPrintf(CONFIG_DBG_MIB_GROUP, "\n\tasGroupAddr[%d] = %x:%x:%x:%x:%x:%x:%x:%x)", u8Group, psMibGroup->sPerm.asGroupAddr[u8Group].s6_addr16[0], psMibGroup->sPerm.asGroupAddr[u8Group].s6_addr16[1], psMibGroup->sPerm.asGroupAddr[u8Group].s6_addr16[2], psMibGroup->sPerm.asGroupAddr[u8Group].s6_addr16[3], psMibGroup->sPerm.asGroupAddr[u8Group].s6_addr16[4], psMibGroup->sPerm.asGroupAddr[u8Group].s6_addr16[5], psMibGroup->sPerm.asGroupAddr[u8Group].s6_addr16[6], psMibGroup->sPerm.asGroupAddr[u8Group].s6_addr16[7]); } } #endif } }
static DWORD WINAPI dwThreadFunction(void *psThreadInfoVoid) #endif /* WIN32 */ { tsUtilsThread *psThreadInfo = (tsUtilsThread *)psThreadInfoVoid; tsThreadPrivate *psThreadPrivate = (tsThreadPrivate *)psThreadInfo->pvPriv; DBG_vPrintf(DBG_THREADS, "Thread %p running for function %p\n", psThreadInfo, psThreadPrivate->prThreadFunction); if (psThreadInfo->eThreadDetachState == E_THREAD_DETACHED) { DBG_vPrintf(DBG_THREADS, "Detach Thread %p\n", psThreadInfo); #ifndef WIN32 if (pthread_detach(psThreadPrivate->thread)) { perror("pthread_detach()"); } #endif /* WIN32 */ } psThreadPrivate->prThreadFunction(psThreadInfo); #ifndef WIN32 pthread_exit(NULL); return NULL; #else return 0; #endif /* WIN32 */ }
/**************************************************************************** * * NAME: vInitialiseApp * * DESCRIPTION: * Initialises Zigbee stack, hardware and application. * * * RETURNS: * void ****************************************************************************/ PRIVATE void vInitialiseApp(void) { /* * Initialise JenOS modules. Initialise Power Manager even on non-sleeping nodes * as it allows the device to doze when in the idle task. * Parameter options: E_AHI_SLEEP_OSCON_RAMON or E_AHI_SLEEP_DEEP or ... */ PWRM_vInit(E_AHI_SLEEP_OSCON_RAMON); #if JENNIC_CHIP == JN5169 PDM_eInitialise(63, NULL); #else PDM_eInitialise(0, NULL); #endif /* Initialise Protocol Data Unit Manager */ PDUM_vInit(); ZPS_vExtendedStatusSetCallback(vfExtendedStatusCallBack); /* Initialise application */ APP_vInitialiseNode(); DBG_vPrintf(TRACE_START, "\nAPP Start: Tick Timer = %d", u32AHI_TickTimerRead()); DBG_vPrintf(TRACE_START,"\nAPP Start: Initialised"); }
/**************************************************************************** * * NAME: MibNwkSecurity_vInit * * DESCRIPTION: * Initialises data * ****************************************************************************/ PUBLIC void MibNwkSecurity_vInit(thJIP_Mib hMibNwkSecurityInit, tsMibNwkSecurity *psMibNwkSecurityInit, bool_t bMibNwkSecuritySecurity) { /* Valid data pointer ? */ if (psMibNwkSecurityInit != (tsMibNwkSecurity *) NULL) { PDM_teStatus ePdmStatus; /* Debug */ DBG_vPrintf(CONFIG_DBG_MIB_NWK_SECURITY, "\nMibNwkSecurity_vInit() {%d}", sizeof(tsMibNwkSecurity)); /* Take copy of pointer to data */ psMibNwkSecurity = psMibNwkSecurityInit; /* Take a copy of the MIB handle */ psMibNwkSecurity->hMib = hMibNwkSecurityInit; /* Note security setting */ psMibNwkSecurity->bSecurity = bMibNwkSecuritySecurity; /* Load NodeStatus mib data */ ePdmStatus = PDM_eLoadRecord(&psMibNwkSecurity->sDesc, #if defined(JENNIC_CHIP_FAMILY_JN514x) "MibNwkSecurity", #else (uint16)(MIB_ID_NWK_SECURITY & 0xFFFF), #endif (void *) &psMibNwkSecurity->sPerm, sizeof(psMibNwkSecurity->sPerm), FALSE); /* Debug */ DBG_vPrintf(CONFIG_DBG_MIB_NWK_SECURITY, "\n\tPDM_eLoadRecord(MibNwkSecurity, %d) = %d", sizeof(psMibNwkSecurity->sPerm), ePdmStatus); } }
/**************************************************************************** * * NAME: vJIP_StackEvent * * DESCRIPTION: * Processes any incoming stack events. * Once a join indication has been received, we initialise JIP and register * the various MIBs. * * PARAMETERS: Name RW Usage * eEvent R Stack event * pu8Data R Additional information associated with event * u8DataLen R Length of additional information * ****************************************************************************/ PUBLIC void vJIP_StackEvent(te6LP_StackEvent eEvent, uint8 *pu8Data, uint8 u8DataLen) { bool_t bPollNoData; /* Debug */ DBG_vPrintf(DEBUG_DEVICE_FUNC, "\nvJIP_StackEvent(%d)", eEvent); /* Node handling */ bPollNoData = Node_bJipStackEvent(eEvent, pu8Data, u8DataLen); /* Allowing sleep ? */ #ifdef MK_BLD_NODE_TYPE_END_DEVICE { /* Did we get a poll response but no data ? */ if (bPollNoData) { /* Set flag for sleep */ bSleep = TRUE; } } #endif /* MIB handling */ MibDioControl_vStackEvent(eEvent); /* Debug */ DBG_vPrintf(DEBUG_DEVICE_FUNC, "\nvJIP_StackEvent(%d) RETURN", eEvent); }
/**************************************************************************** * * NAME: vOSError * * DESCRIPTION: * Catches any unexpected OS errors * * RETURNS: * void * ****************************************************************************/ PUBLIC void vOSError(OS_teStatus eStatus, void *hObject) { OS_thTask hTask; /* ignore queue underruns */ if ((OS_E_QUEUE_EMPTY == eStatus) || ((eStatus >= OS_E_SWTIMER_STOPPED) && (eStatus <= OS_E_SWTIMER_RUNNING))) { return; } DBG_vPrintf(TRACE_EXCEPTION, "OS Error %d, offending object handle = 0x%08x\n", eStatus, hObject); /* NB the task may have been pre-empted by an ISR which may be at fault */ OS_eGetCurrentTask(&hTask); DBG_vPrintf(TRACE_EXCEPTION, "Currently active task handle = 0x%08x\n", hTask); #ifdef OS_STRICT_CHECKS DBG_vPrintf(TRACE_EXCEPTION, "Currently active ISR fn address = 0x%08x\n", OS_prGetActiveISR()); #endif #if HALT_ON_EXCEPTION DBG_vDumpStack(); if ((eStatus < OS_E_SWTIMER_STOPPED) || (eStatus > OS_E_SWTIMER_RUNNING)) { while(1); } #endif }
/**************************************************************************** * * NAME: MibNwkConfigPatch_vSetUserData * * DESCRIPTION: * Puts wanted network id into establish route requests and beacon responses * ****************************************************************************/ PUBLIC void MibNwkConfigPatch_vSetUserData(void) { tsBeaconUserData sBeaconUserData; /* Debug */ DBG_vPrintf(CONFIG_DBG_MIB_NWK_CONFIG, "\nMibNwkConfigPatch_vSetUserData()"); /* Set up user data */ sBeaconUserData.u32NetworkId = psMibNwkConfig->sPerm.u32NetworkId; sBeaconUserData.u16DeviceType = MK_JIP_DEVICE_TYPE; /* Set beacon payload */ vApi_SetUserBeaconBits((uint8 *) &sBeaconUserData); /* Debug */ DBG_vPrintf(CONFIG_DBG_MIB_NWK_CONFIG, "\n\tvApi_SetUserBeaconBits(%x, %x)", sBeaconUserData.u32NetworkId, sBeaconUserData.u16DeviceType); /* Set up beacon response callback */ vApi_RegBeaconNotifyCallback(MibNwkConfigPatch_bBeaconNotifyCallback); /* Set establish route payload */ v6LP_SetUserData(sizeof(tsBeaconUserData), (uint8 *) &sBeaconUserData); /* Debug */ DBG_vPrintf(CONFIG_DBG_MIB_NWK_CONFIG, "\n\tv6LP_SetUserData(%x, %x)", sBeaconUserData.u32NetworkId, sBeaconUserData.u16DeviceType); /* Set up establish route callback */ v6LP_SetNwkCallback(MibNwkConfigPatch_bNwkCallback); /* Set device types */ vJIP_SetDeviceTypes(1, &u16DeviceType); }
void vApp_RegisterGPDevice(tfpZCL_ZCLCallBackFunction fptrEPCallBack) { teZCL_Status eZCL_Status; teGP_ResetToDefaultConfig eResetToDefault = E_GP_DEFAULT_ATTRIBUTE_VALUE |E_GP_DEFAULT_SINK_TABLE_VALUE |E_GP_DEFAULT_PROXY_TABLE_VALUE; #ifdef GP_COMBO_MIN_DEVICE /* Register GP End Point */ eZCL_Status = eGP_RegisterComboMinimumEndPoint( GREENPOWER_END_POINT_ID, fptrEPCallBack, &sDeviceInfo, HA_PROFILE_ID, GP_NUMBER_OF_TRANSLATION_TABLE_ENTRIES, sGPPDMData.asTranslationTableEntry); /* Check GP end point registration status */ if (eZCL_Status != E_ZCL_SUCCESS) { DBG_vPrintf(TRACE_APP_GP, "Error: eGP_RegisterComboMinimumEndPoint:%d\r\n", eZCL_Status); } if(RESTORE_GP_DATA == sGPPDMData.u8RestoreDefaults) { tsGP_PersistedData sGPData; DBG_vPrintf(TRACE_APP_GP, "sGPPDMData.u8RestoreDefaults = %d \n", sGPPDMData.u8RestoreDefaults); /* DO not reset sink table to default. Sink table is persisted */ eResetToDefault = E_GP_DEFAULT_ATTRIBUTE_VALUE ; sGPData.pasZgpsSinkTable = (sDeviceInfo.sGreenPowerCustomDataStruct.asZgpsSinkTable); vGP_RestorePersistedData(&sGPData,eResetToDefault); } else { DBG_vPrintf(TRACE_APP_GP, "sGPPDMData.u8RestoreDefaults = %d should not be %d \n", sGPPDMData.u8RestoreDefaults, RESTORE_GP_DATA); vGP_RestorePersistedData(NULL,eResetToDefault); memset(&sGPPDMData.asGpToZclCmdInfoUpdate,0, sizeof(sGPPDMData.asGpToZclCmdInfoUpdate) ); } sDeviceInfo.sServerGreenPowerCluster.b24ZgpsFeatures |= ( GP_FEATURE_ZGPD_SEC_LVL_0B01 | GP_FEATURE_ZGPD_SEC_LVL_0B10); sDeviceInfo.sServerGreenPowerCluster.b24ZgpsFeatures |= GP_FEATURE_CT_BASED_CMSNG; sDeviceInfo.sServerGreenPowerCluster.b8ZgpsSecLevel = GP_SECURITY_LEVEL; #ifdef GP_SECURITY sDeviceInfo.sServerGreenPowerCluster.b8ZgpSharedSecKeyType = GP_KEYTPE; #ifdef CLD_GP_ATTR_ZGP_LINK_KEY memcpy(&(sDeviceInfo.sServerGreenPowerCluster.sZgpLinkKey),s_au8LnkKeyArray, 16 ); #endif #ifdef GPD_SEC_PRECONFIG_MODE uint8 key[] = GP_SHARED_KEY; memcpy(&sDeviceInfo.sServerGreenPowerCluster.sZgpSharedSecKey,key, 16 ); #endif #endif #endif }
/**************************************************************************** * * NAME: vSendDelayedCommands * * DESCRIPTION: * Sends the delayed commands in the individual control or commissioning mode * * RETURNS: * void * ****************************************************************************/ PRIVATE void vSendDelayedCommands(te_TransitionCode eTransitionCode) { DBG_vPrintf(TRACE_SWITCH_STATE,"\nIn vSendDelayedCommands with TransitionCode = %d -> ",eTransitionCode); switch(eTransitionCode) { case ON_PRESSED: DBG_vPrintf(TRACE_SWITCH_STATE," E_CLD_ONOFF_CMD_ON \n"); vAppOnOff(E_CLD_ONOFF_CMD_ON); break; case OFF_PRESSED: DBG_vPrintf(TRACE_SWITCH_STATE," E_CLD_ONOFF_CMD_OFF \n"); vAppOnOff(E_CLD_ONOFF_CMD_OFF); break; case UP_PRESSED: DBG_vPrintf(TRACE_SWITCH_STATE," E_CLD_LEVELCONTROL_MOVE_MODE_UP \n"); vAppLevelMove(E_CLD_LEVELCONTROL_MOVE_MODE_UP, 65, TRUE); break; case DOWN_PRESSED: DBG_vPrintf(TRACE_SWITCH_STATE," E_CLD_LEVELCONTROL_MOVE_MODE_DOWN \n"); vAppLevelMove(E_CLD_LEVELCONTROL_MOVE_MODE_DOWN, 65, FALSE); break; default : break; } vDQButtonPress(); }
tsNode *psJIP_NodeListRemove(tsNode **ppsNodeListHead, tsNode *psNode) { DBG_vPrintf(DBG_FUNCTION_CALLS, "%s Remove Node %p from list head %p\n", __FUNCTION__, psNode, *ppsNodeListHead); vJIP_NodeListPrint(ppsNodeListHead); if (*ppsNodeListHead == psNode) { DBG_vPrintf(DBG_NODES, "Remove Node %p from head of list\n", psNode); *ppsNodeListHead = (*ppsNodeListHead)->psNext; } else { tsNode *psllPosition = *ppsNodeListHead; while (psllPosition->psNext) { if (psllPosition->psNext == psNode) { DBG_vPrintf(DBG_NODES, "Remove Node %p from list at %p\n", psNode, psllPosition->psNext); psllPosition->psNext = psllPosition->psNext->psNext; break; } psllPosition = psllPosition->psNext; } } vJIP_NodeListPrint(ppsNodeListHead); return NULL; }
/**************************************************************************** * * NAME: MibNwkSecurity_vSetProfile * * DESCRIPTION: * Set network operating profile according to network mode * ****************************************************************************/ PATCH_POINT_PUBLIC(void,MibNwkSecurity_vSetProfile)(bool_t bStandalone) { /* Debug */ DBG_vPrintf(CONFIG_DBG_MIB_NWK_SECURITY, "\nMibNwkSecurity_vSetProfile(%d)", bStandalone); /* Standalone system ? */ if (bStandalone) { tsNwkProfile sNwkProfile; /* Read network profile */ vJnc_GetNwkProfile(&sNwkProfile); /* Inhibit pings */ sNwkProfile.u8MaxFailedPkts = 0; sNwkProfile.u16RouterPingPeriod = 0; /* Apply as user profile */ (void) bJnc_SetRunProfile(PROFILE_USER, &sNwkProfile); /* Debug */ DBG_vPrintf(CONFIG_DBG_MIB_NWK_SECURITY, "\n\tbJnc_SetRunProfile(USER)"); /* Inhibit End Device activity timeout */ psMibNwkSecurity->psNetworkConfigData->u32EndDeviceActivityTimeout = 0; } /* Gateway system ? */ else { /* Apply default run profile for joining gateway system - will be updated if necessary upon joining */ (void) bJnc_SetRunProfile(0, NULL); /* Debug */ DBG_vPrintf(CONFIG_DBG_MIB_NWK_SECURITY, "\n\tbJnc_SetRunProfile(0)"); /* Apply gateway end device activity timeout settings */ psMibNwkSecurity->psNetworkConfigData->u32EndDeviceActivityTimeout = psMibNwkSecurity->u32EndDeviceActivityTimeout; } }
/**************************************************************************** * * NAME: APP_ZCL_vInitialise * * DESCRIPTION: * Initialises ZCL related functions * * RETURNS: * void * ****************************************************************************/ PUBLIC void APP_ZCL_vInitialise(void) { teZCL_Status eZCL_Status; /* Initialise ZHA */ eZCL_Status = eHA_Initialise(&APP_ZCL_cbGeneralCallback, apduZCL); if (eZCL_Status != E_ZCL_SUCCESS) { DBG_vPrintf(TRACE_ZCL, "\nAPP_ZCL: Error eHA_Initialise returned %d", eZCL_Status); } /* Register ZHA EndPoint */ eZCL_Status = eApp_HA_RegisterEndpoint(&APP_ZCL_cbEndpointCallback); if (eZCL_Status != E_ZCL_SUCCESS) { DBG_vPrintf(TRACE_SENSOR_TASK, "\nAPP_ZCL: Error: eApp_HA_RegisterEndpoint:%d", eZCL_Status); } DBG_vPrintf(TRACE_SENSOR_TASK, "\nAPP_ZCL: Chan Mask %08x", ZPS_psAplAibGetAib()->apsChannelMask); DBG_vPrintf(TRACE_SENSOR_TASK, "\nAPP_ZCL: RxIdle TRUE"); OS_eStartSWTimer(APP_TickTimer, ZCL_TICK_TIME, NULL); vAPP_ZCL_DeviceSpecific_Init(); }
teJIP_Status eGroups_GroupClearSet(tsVar *psVar, tsJIPAddress *psDstAddress) { tsMib *psMib = psVar->psOwnerMib; tsNode *psNode = psMib->psOwnerNode; tsNode_Private *psNode_Private = (tsNode_Private *)psNode->pvPriv; int iGroupAddressSlot; struct in6_addr sBlankAddress; char acAddr[INET6_ADDRSTRLEN] = "Could not determine address\n"; memset(&sBlankAddress, 0, sizeof(struct in6_addr)); DBG_vPrintf(DBG_FUNCTION_CALLS, "%s\n", __FUNCTION__); /* Iterate over all groups */ for (iGroupAddressSlot = 0; iGroupAddressSlot < JIP_DEVICE_MAX_GROUPS; iGroupAddressSlot++) { if (memcmp(&psNode_Private->asGroupAddresses[iGroupAddressSlot], &sBlankAddress, sizeof(struct in6_addr))) { DBG_vPrintf(DBG_GROUPS, "%s: Leave group ", __FUNCTION__); DBG_vPrintf_IPv6Address(DBG_GROUPS, psNode_Private->asGroupAddresses[iGroupAddressSlot]); inet_ntop(AF_INET6, &psNode_Private->asGroupAddresses[iGroupAddressSlot], acAddr, INET6_ADDRSTRLEN); eJIPserver_NodeGroupLeave(psNode, acAddr); } } return E_JIP_OK; }
tsNode *psJIP_NetAllocateNode(tsNetwork *psNet, tsJIPAddress *psAddress, uint32_t u32DeviceId) { tsNode *psNewNode; DBG_vPrintf(DBG_FUNCTION_CALLS, "%s to Net at %p\n", __FUNCTION__, psNet); psNewNode = malloc(sizeof(tsNode)); if (!psNewNode) { DBG_vPrintf(DBG_NODES, "Error allocating space for Node\n"); return NULL; } memset(psNewNode, 0, sizeof(tsNode)); psNewNode->psOwnerNetwork = psNet; if (psAddress) { psNewNode->sNode_Address = *psAddress; } psNewNode->u32DeviceId = u32DeviceId; eLockCreate(&psNewNode->sLock); eJIPLockLock(&psNewNode->sLock); DBG_vPrintf(DBG_NODES, "New Node allocated at %p\n", psNewNode); DBG_vPrintf_IPv6Address(DBG_NODES, psNewNode->sNode_Address.sin6_addr); return psNewNode; }
/**************************************************************************** * NAME: bProcessGPDEvent * * DESCRIPTION: * Handles SW1 functionalities * * RETURNS: * Return whether device can go to sleep * ****************************************************************************/ bool bProcessGPDEvent(void) { bool bEnableSleep = TRUE; /* send command based on the state the device is in */ HandleGPDStateMachine(0); #ifdef DK4 /** wait till short press time is elapsed , enabling interrupts . If next * short press is initiated, interrupt should be fired while this time interval */ /* wait till button release */ bButtonPressed = FALSE; uint32 u32DIOVal = u32AHI_DioReadInput(); uint32 u32DIOVal2 = u32AHI_DioReadInput(); while(u32DIOVal2 == u32DIOVal) { u32DIOVal = u32AHI_DioReadInput(); } /* stop timer if already running (by previous button press )*/ vEH_StopTimer(); uint32 u32StartTime; /* start timer to account next button press interval */ u32StartTime = u32EH_StartTimer(); u32Button = 0; (void) u32AHI_DioInterruptStatus(); vAHI_DioInterruptEnable(APP_BUTTONS_DIO_MASK, 0); while( 1) { if(bEH_IsTimeElapsedInMicrosSec( APP_TIME_MS(SHORT_PRESS_TIME) ,u32StartTime)) { vEH_StopTimer(); sGPDData.u8ButtonCount = 0; DBG_vPrintf(DBG_DEVICE_SWITCH, "\n short press timer expired \n" ); break; } if((u32Button == APP_E_BUTTONS_BUTTON_SW1)|| (u32Button == APP_E_BUTTONS_BUTTON_SW2) || (u32Button == APP_E_BUTTONS_BUTTON_SW3)|| (u32Button == APP_E_BUTTONS_BUTTON_SW4) ) { bEnableSleep = FALSE; (void) u32AHI_DioInterruptStatus(); DBG_vPrintf(DBG_DEVICE_SWITCH, "\n short press timer detected \n" ); break; } } #endif return bEnableSleep; }
teUtilsStatus eUtils_ThreadWait(tsUtilsThread *psThreadInfo) { tsThreadPrivate *psThreadPrivate = (tsThreadPrivate *)psThreadInfo->pvPriv; DBG_vPrintf(DBG_THREADS, "Wait for Thread %p\n", psThreadInfo); if (psThreadPrivate) { if (psThreadInfo->eThreadDetachState == E_THREAD_JOINABLE) { #if defined POSIX /* Thread is joinable */ if (pthread_join(psThreadPrivate->thread, NULL)) { perror("Could not join thread"); return E_UTILS_ERROR_FAILED; } #elif defined WIN32 WaitForSingleObject(psThreadPrivate->thread_handle, INFINITE); #endif /* We can now free the thread private info */ free(psThreadPrivate); } else { DBG_vPrintf(DBG_THREADS, "Cannot join detached thread %p\n", psThreadInfo); return E_UTILS_ERROR_FAILED; } } psThreadInfo->eState = E_THREAD_STOPPED; return E_UTILS_OK; }
void vJIPserver_GroupMibCompressedAddressToIn6(struct in6_addr *psAddress, uint8_t *pau8Buffer, uint8_t u8BufferLength) { int i; DBG_vPrintf(DBG_FUNCTION_CALLS, "%s ", __FUNCTION__); for (i = 0; i < u8BufferLength; i++) { DBG_vPrintf(DBG_FUNCTION_CALLS, "0x%02x ", pau8Buffer[i]); } DBG_vPrintf(DBG_FUNCTION_CALLS, "\n"); memset(psAddress, 0, sizeof(struct in6_addr)); psAddress->s6_addr[0] = 0xFF; psAddress->s6_addr[1] = pau8Buffer[0]; for (i = 15; u8BufferLength > 1; u8BufferLength--, i--) { psAddress->s6_addr[i] = pau8Buffer[u8BufferLength-1]; } DBG_vPrintf(DBG_FUNCTION_CALLS, "%s Result: ", __FUNCTION__); DBG_vPrintf_IPv6Address(DBG_FUNCTION_CALLS, *psAddress); return; }
/**************************************************************************** * * NAME: vManageIndividualControlMode * * DESCRIPTION: * Manage the Individual control modes for the lights in unicast mode * * RETURNS: * void * ****************************************************************************/ PRIVATE void vManageIndividualControlMode(te_SwitchState *peSwitchState, te_TransitionCode eTransitionCode ) { /* Calls individual function * Changes state * Addressing for individual functions * Individual or group ? - well the address will be taken based on the state */ DBG_vPrintf(TRACE_SWITCH_STATE,"\nIn vManageIndividualControlMode(Mode = %d) TransitionCode = %d -> ", *peSwitchState,eTransitionCode); switch(eTransitionCode) { /* Fall through for the button presses as there will be a delayed action*/ case ON_PRESSED: case OFF_PRESSED: case UP_PRESSED: case DOWN_PRESSED: vQButtonPress(eTransitionCode); break; case UP_AND_ON_TOGETHER_PRESSED: vDQButtonPress(); DBG_vPrintf(TRACE_SWITCH_STATE," vAppStoreSceneById = 1 \n"); vAppStoreSceneById(SCENE_1, u16GroupId); *peSwitchState = LIGHT_CONTROL_MODE; break; case DOWN_AND_OFF_TOGETHER_PRESSED: vDQButtonPress(); DBG_vPrintf(TRACE_SWITCH_STATE," vAppStoreSceneById = 2 \n"); vAppStoreSceneById(SCENE_2, u16GroupId); *peSwitchState = LIGHT_CONTROL_MODE; break; case COMM_BUTTON_PRESSED: *peSwitchState = IDENTIFY_MODE; vAppDiscover(); break; case DOWN_RELEASED: case UP_RELEASED: vDQButtonPress(); DBG_vPrintf(TRACE_SWITCH_STATE," vAppLevelStop \n"); vAppLevelStop(); break; default : break; } /*Restart the Timer from expiring */ if( OS_eGetSWTimerStatus(App_ChangeModeTimer) == OS_E_SWTIMER_EXPIRED ) { OS_eStopSWTimer(App_ChangeModeTimer); *peSwitchState = LIGHT_CONTROL_MODE; } else vStopStartModeChangeTimer(APP_TIME_MS(30000)); }
tsVar *psJIP_MibAddVar(tsMib *psMib, uint8_t u8Index, const char *pcName, teJIP_VarType eVarType, teJIP_AccessType eAccessType, teJIP_Security eSecurity) { tsVar *NewVar; DBG_vPrintf(DBG_FUNCTION_CALLS, "%s(%s) to Mib 0x%08x at %p\n", __FUNCTION__, pcName, psMib->u32MibId, psMib); NewVar = malloc(sizeof(tsVar)); if (!NewVar) { DBG_vPrintf(DBG_VARS, "Error allocating space for Var\n"); return NULL; } memset(NewVar, 0, sizeof(tsVar)); NewVar->pcName = strdup(pcName); NewVar->u8Index = u8Index; NewVar->eVarType = eVarType; NewVar->eAccessType = eAccessType; NewVar->eSecurity = eSecurity; NewVar->psOwnerMib = psMib; NewVar->eEnable = E_JIP_VAR_ENABLED; /* All vars enabled by default */ psMib->u32NumVars++; DBG_vPrintf(DBG_VARS, "New Var allocated at %p, name at %p\n", NewVar, NewVar->pcName); /* Insert the new Mib into the linked list of Mibs */ if (psMib->psVars == NULL) { /* First in list */ psMib->psVars = NewVar; } else { tsVar *psllPosition = psMib->psVars; while (psllPosition->psNext) { psllPosition = psllPosition->psNext; } /* Now we have a pointer to the last element in the list */ psllPosition->psNext = NewVar; } { tsVar *psllPosition = psMib->psVars; DBG_vPrintf(DBG_VARS, "Vars Head %p, next: %p\n", psllPosition, psllPosition->psNext); while (psllPosition->psNext) { psllPosition = psllPosition->psNext; DBG_vPrintf(DBG_VARS, " Var at %p, next: %p\n", psllPosition, psllPosition->psNext); } } return NewVar; }
/**************************************************************************** * * NAME: vAppAddTransTableEntries * * DESCRIPTION: * GP translation table addition during commissioning * * RETURNS: * void * ****************************************************************************/ void vAppAddTransTableEntries( uint8 u8TransEntries, tuGP_ZgpdDeviceAddr uRcvdGPDAddr, zbmap8 b8Options, tsGP_GpToZclCommandInfo *pCmdInfo) { uint8 u8Count = 0; tsGP_TranslationTableEntry *psTranslationTableEntry; /* uDummydeviceAddr will be used to get a unused/free entry from translation table */ tuGP_ZgpdDeviceAddr uDummydeviceAddr = { 0 }; if(u8TransEntries == 0) { return; } /* Check if previous entry with the same device exists, delete all such entries * if any */ for(u8Count = 0; u8Count < GP_NUMBER_OF_TRANSLATION_TABLE_ENTRIES; u8Count++) { psTranslationTableEntry = psApp_GPGetTranslationTable(&(uRcvdGPDAddr)); if( psTranslationTableEntry == NULL ) { break; } else { if(psTranslationTableEntry->psGpToZclCmdInfo->u8EndpointId != 0xFD) { /* clear entry */ memset(&psTranslationTableEntry->uZgpdDeviceAddr, 0, sizeof(tuGP_ZgpdDeviceAddr)); DBG_vPrintf(TRACE_APP_GP, "cleared translation table \n"); } } } u32GPDSrcID = uRcvdGPDAddr.u32ZgpdSrcId; /* Now add translation table entry for each command supported */ DBG_vPrintf(TRACE_APP_GP, "adding commands \n"); /* get free translation entry( entry with 0x00(uDummydeviceAddr) as src id )*/ psTranslationTableEntry = psApp_GPGetTranslationTable(&uDummydeviceAddr); /* check pointer */ if(psTranslationTableEntry != NULL) { psTranslationTableEntry->b8Options = b8Options; psTranslationTableEntry->uZgpdDeviceAddr = uRcvdGPDAddr; psTranslationTableEntry->psGpToZclCmdInfo = &(pCmdInfo[0]) ; psTranslationTableEntry->u8NoOfCmdInfo = u8TransEntries; DBG_vPrintf(TRACE_APP_GP, "ENTRY ADDED TO THE TABLE = 0x%x\n", psTranslationTableEntry->psGpToZclCmdInfo->eZgpdCommandId); } }
/**************************************************************************** * * NAME: MibNodeControl_vRegister * * DESCRIPTION: * Registers MIB * ****************************************************************************/ PUBLIC void MibNodeControl_vRegister(void) { teJIP_Status eStatus; /* Register MIB */ eStatus = eJIP_RegisterMib(psMibNodeControl->hMib); /* Debug */ DBG_vPrintf(CONFIG_DBG_MIB_NODE_CONTROL, "\nMibNodeControl_vRegister()"); DBG_vPrintf(CONFIG_DBG_MIB_NODE_CONTROL, "\n\teJIP_RegisterMib(NodeControl)=%d", eStatus); }
/**************************************************************************** * * NAME: vDisplayPDMUsage * * DESCRIPTION: * Displays the PDM capacity and current occupancy * * RETURNS: * void * ****************************************************************************/ PUBLIC void vDisplayPDMUsage(void) { #ifdef PDM_EEPROM /* * The functions u8PDM_CalculateFileSystemCapacity and u8PDM_GetFileSystemOccupancy * may be called at any time to monitor space available in the eeprom */ DBG_vPrintf(TRACE_PDM, "\r\nPDM: Capacity %d\n", u8PDM_CalculateFileSystemCapacity() ); DBG_vPrintf(TRACE_PDM, "\r\nPDM: Occupancy %d\n", u8PDM_GetFileSystemOccupancy() ); #endif }
teUtilsStatus eUtils_QueueQueue(tsUtilsQueue *psQueue, void *pvData) { tsQueuePrivate *psQueuePrivate = (tsQueuePrivate*)psQueue->pvPriv; DBG_vPrintf(DBG_QUEUE, "Queue %p: Queue %p\n", psQueue, pvData); #ifndef WIN32 pthread_mutex_lock (&psQueuePrivate->mMutex); #else EnterCriticalSection (&psQueuePrivate->hMutex); #endif /* WIN32 */ DBG_vPrintf(DBG_QUEUE, "Got mutex on queue %p (size = %d)\n", psQueue, psQueuePrivate->u32Size); if (psQueuePrivate->iFlags & UTILS_QUEUE_NONBLOCK_INPUT) { // Check if buffer is full and return if so. if (psQueuePrivate->u32Size == psQueuePrivate->u32Capacity) { DBG_vPrintf(DBG_QUEUE, "Queue full, could not enqueue entry\n"); #ifndef WIN32 pthread_mutex_unlock (&psQueuePrivate->mMutex); #else LeaveCriticalSection (&psQueuePrivate->hMutex); #endif /* WIN32 */ return E_UTILS_ERROR_BLOCK; } } else { // Block until space is available while (psQueuePrivate->u32Size == psQueuePrivate->u32Capacity) #ifndef WIN32 pthread_cond_wait (&psQueuePrivate->cond_space_available, &psQueuePrivate->mMutex); #else SleepConditionVariableCS(&psQueuePrivate->hSpaceAvailable, &psQueuePrivate->hMutex, INFINITE); #endif /* WIN32 */ } psQueuePrivate->apvBuffer[psQueuePrivate->u32In] = pvData; psQueuePrivate->u32Size++; psQueuePrivate->u32In = (psQueuePrivate->u32In+1) % psQueuePrivate->u32Capacity; #ifndef WIN32 pthread_mutex_unlock (&psQueuePrivate->mMutex); pthread_cond_broadcast (&psQueuePrivate->cond_data_available); #else LeaveCriticalSection (&psQueuePrivate->hMutex); WakeConditionVariable (&psQueuePrivate->hDataAvailable); #endif /* WIN32 */ DBG_vPrintf(DBG_QUEUE, "Queue %p: Queued %p\n", psQueue, pvData); return E_UTILS_OK; }
tsMib *psJIP_NodeAddMib(tsNode *psNode, uint32_t u32MibId, uint8_t u8Index, const char *pcName) { tsMib *NewMib; DBG_vPrintf(DBG_FUNCTION_CALLS, "%s(0x%08x, %s) to Node at %p\n", __FUNCTION__, u32MibId, pcName, psNode); NewMib = malloc(sizeof(tsMib)); if (!NewMib) { DBG_vPrintf(DBG_MIBS, "Error allocating space for Mib\n"); return NULL; } memset(NewMib, 0, sizeof(tsMib)); NewMib->u32MibId = u32MibId; NewMib->u8Index = u8Index; NewMib->pcName = strdup(pcName); NewMib->psOwnerNode = psNode; psNode->u32NumMibs++; DBG_vPrintf(DBG_MIBS, "New Mib allocated at %p, name at %p\n", NewMib, NewMib->pcName); /* Insert the new Mib into the linked list of Mibs */ if (psNode->psMibs == NULL) { /* First in list */ psNode->psMibs = NewMib; } else { tsMib *psllPosition = psNode->psMibs; while (psllPosition->psNext) { psllPosition = psllPosition->psNext; } /* Now we have a pointer to the last element in the list */ psllPosition->psNext = NewMib; } { tsMib *psllPosition = psNode->psMibs; DBG_vPrintf(DBG_MIBS, "Mibs Head %p, next: %p\n", psllPosition, psllPosition->psNext); while (psllPosition->psNext) { psllPosition = psllPosition->psNext; DBG_vPrintf(DBG_MIBS, " Mib at %p, next: %p\n", psllPosition, psllPosition->psNext); } } return NewMib; }
static inline void vJIP_NodeListPrint(tsNode **ppsNodeListHead) { #if DBG_NODES tsNode *psllPosition = *ppsNodeListHead; DBG_vPrintf(DBG_NODES, "Node List: Head %p\n", psllPosition); while (psllPosition) { DBG_vPrintf(DBG_NODES, "Node List: Node %p, next: %p\n", psllPosition, psllPosition->psNext); psllPosition = psllPosition->psNext; } #endif /* DBG_NODES */ }
teUtilsStatus eUtils_QueueDequeue(tsUtilsQueue *psQueue, void **ppvData) { tsQueuePrivate *psQueuePrivate = (tsQueuePrivate*)psQueue->pvPriv; DBG_vPrintf(DBG_QUEUE, "Queue %p: Dequeue\n", psQueue); #ifndef WIN32 pthread_mutex_lock (&psQueuePrivate->mMutex); #else EnterCriticalSection (&psQueuePrivate->hMutex); #endif /* WIN32 */ DBG_vPrintf(DBG_QUEUE, "Got mutex on queue %p (size=%d)\n", psQueue, psQueuePrivate->u32Size); if (psQueuePrivate->iFlags & UTILS_QUEUE_NONBLOCK_OUTPUT) { // Check if buffer is empty and return if so. if (psQueuePrivate->u32Size == 0) { DBG_vPrintf(DBG_QUEUE, "Queue empty\n"); #ifndef WIN32 pthread_mutex_unlock (&psQueuePrivate->mMutex); #else LeaveCriticalSection (&psQueuePrivate->hMutex); #endif /* WIN32 */ return E_UTILS_ERROR_BLOCK; } } else { // Wait for data to become available while (psQueuePrivate->u32Size == 0) #ifndef WIN32 pthread_cond_wait (&psQueuePrivate->cond_data_available, &psQueuePrivate->mMutex); #else SleepConditionVariableCS(&psQueuePrivate->hDataAvailable, &psQueuePrivate->hMutex, INFINITE); #endif /* WIN32 */ } *ppvData = psQueuePrivate->apvBuffer[psQueuePrivate->u32Out]; psQueuePrivate->u32Size--; psQueuePrivate->u32Out = (psQueuePrivate->u32Out + 1) % psQueuePrivate->u32Capacity; #ifndef WIN32 pthread_mutex_unlock (&psQueuePrivate->mMutex); pthread_cond_broadcast (&psQueuePrivate->cond_space_available); #else LeaveCriticalSection (&psQueuePrivate->hMutex); WakeConditionVariable (&psQueuePrivate->hSpaceAvailable); #endif /* WIN32 */ DBG_vPrintf(DBG_QUEUE, "Queue %p: Dequeued %p\n", psQueue, *ppvData); return E_UTILS_OK; }
/**************************************************************************** * * NAME: MibNodeStatus_vRegister * * DESCRIPTION: * Registers MIB * ****************************************************************************/ PUBLIC void MibNodeStatus_vRegister(void) { teJIP_Status eStatus; /* Register MIB */ eStatus = eJIP_RegisterMib(psMibNodeStatus->hMib); /* Debug */ DBG_vPrintf(CONFIG_DBG_MIB_NODE_STATUS, "\nMibNodeStatus_vRegister()"); DBG_vPrintf(CONFIG_DBG_MIB_NODE_STATUS, "\n\teJIP_RegisterMib(NodeStatus)=%d", eStatus); /* Make sure permament data is saved */ psMibNodeStatus->bSaveRecord = TRUE; }
/**************************************************************************** * * NAME: MibNwkSecurity_vRegister * * DESCRIPTION: * Registers MIB * ****************************************************************************/ PUBLIC void MibNwkSecurity_vRegister(void) { teJIP_Status eStatus; /* Register MIB */ eStatus = eJIP_RegisterMib(psMibNwkSecurity->hMib); /* Debug */ DBG_vPrintf(CONFIG_DBG_MIB_NWK_SECURITY, "\nMibNwkSecurity_vRegister()"); DBG_vPrintf(CONFIG_DBG_MIB_NWK_SECURITY, "\n\teJIP_RegisterMib(NwkSecurity)=%d", eStatus); /* Make sure permament data is saved */ psMibNwkSecurity->bSaveRecord = TRUE; }