throughputTest.c

Back to Throughput Test sample application.

00001 
00017 #include "throughputTest.h"
00018 
00019 #ifdef TEST_NETWORK
00020   #undef _BUTTONS_
00021   #undef _SLIDERS_
00022 #endif // TEST_NETWORK
00023 
00024 #define TIMER_STARTING_NETWORK 500 // Period of blinking during starting network
00025 
00026 typedef enum  // Application states
00027 {
00028   APP_INITING_STATE,
00029   APP_NETWORK_STARTING_STATE,
00030   APP_IN_NETWORK_STATE,
00031   APP_NO_NETWORK_STATE
00032 } AppState_t;
00033 
00034 /***********************************************************************************
00035   Global variables
00036 ***********************************************************************************/
00037 DeviceType_t   appDeviceType; // Device type (Coordinator/Router/End device)
00038 uint64_t       appUid;      // Unique ID of the device
00039 APS_RegisterEndpointReq_t endpointParams; // Endpoint parameters
00040 
00041 /***********************************************************************************
00042   Local variables
00043  ***********************************************************************************/
00044 static AppState_t             appState = APP_INITING_STATE; // Current application state
00045 static ZDO_StartNetworkReq_t  networkParams; // Start network request parameters
00046 
00047 // Endpoint parameters
00048 static SimpleDescriptor_t simpleDescriptor = {END_POINT, 1, 1, 1, 0, 0 , NULL, 0, NULL};
00049 
00050 static HAL_AppTimer_t  startingNetworkTimer; // Timer indicating starting network
00051 static HAL_AppTimer_t  delayTimer; // Timer period of waiting after network start
00052 
00053 /***********************************************************************************
00054   Local functions
00055  ***********************************************************************************/
00056 static void ZDO_StartNetworkConf(ZDO_StartNetworkConf_t *confirmInfo); // Network start/join confirmation callback
00057 
00058 /********************************************************************
00059   Description: Network starting timer has fired. Toggle indication
00060 
00061   Parameters: none.
00062 
00063   Returns: nothing.
00064 ********************************************************************/
00065 void startingNetworkTimerFired(void)
00066 {
00067   BSP_ToggleLed(NETWORK_LED);
00068 }
00069 
00070 /********************************************************************
00071   Description: Application task handler
00072 
00073   Parameters: none.
00074 
00075   Returns: nothing.
00076 ********************************************************************/
00077 void APL_TaskHandler(void)
00078 {
00079   uint8_t sliders;
00080 
00081   switch (appState)
00082   {
00083     // Node has initial state
00084     case APP_INITING_STATE:
00085 
00086 #ifdef _LEDS_
00087       BSP_OpenLeds();
00088 #endif //_LEDS_
00089       endpointParams.simpleDescriptor = &simpleDescriptor;
00090 
00091 #ifdef _SLIDERS_
00092       sliders = BSP_ReadSliders();
00093 #else
00094       sliders = 0x00;
00095   #ifdef APP_DEV_TYPE_COORDINATOR
00096       sliders |= SLIDER0;
00097   #elif defined APP_DEV_TYPE_ROUTER
00098       sliders |= SLIDER1;
00099   #elif defined APP_DEV_TYPE_ENDDEVICE
00100       sliders |= SLIDER2;
00101   #endif
00102 #endif //_SLIDERS_
00103 
00104       // Setting device type
00105       if (sliders & SLIDER0)
00106       {
00107         // Coordinator
00108         appDeviceType = DEVICE_TYPE_COORDINATOR;
00109         endpointParams.APS_DataInd = APS_DataIndCoord;
00110       }
00111       else
00112       {
00113         // All other states mean Router
00114         appDeviceType = DEVICE_TYPE_ROUTER;
00115         endpointParams.APS_DataInd = NULL;
00116       }
00117       CS_WriteParameter(CS_DEVICE_TYPE_ID, &appDeviceType);
00118 #if defined(APP_UID)
00119       appUid = APP_UID;
00120 #else
00121       if (DEVICE_TYPE_COORDINATOR == appDeviceType)
00122         appUid = COORDINATOR_EXT_PANID;
00123       else    
00124         HAL_ReadUid(&appUid);
00125 #endif
00126       CS_WriteParameter(CS_UID_ID, &appUid);
00127       appInitUARTManager();  // Init UART manager
00128 
00129       // Configure and start network starting timer
00130       startingNetworkTimer.interval = TIMER_STARTING_NETWORK;
00131       startingNetworkTimer.mode     = TIMER_REPEAT_MODE;
00132       startingNetworkTimer.callback = startingNetworkTimerFired;
00133       HAL_StartAppTimer(&startingNetworkTimer);
00134 
00135       appState = APP_NETWORK_STARTING_STATE; // Switch state
00136       SYS_PostTask(APL_TASK_ID);
00137       break;
00138 
00139     case APP_NETWORK_STARTING_STATE:
00140       {
00141         // Configure network start parameters
00142         uint32_t chMask = CS_CHANNEL_MASK;
00143         ExtAddr_t extPanId = COORDINATOR_EXT_PANID;
00144 
00145         networkParams.ZDO_StartNetworkConf = ZDO_StartNetworkConf;
00146         CS_WriteParameter(CS_CHANNEL_MASK_ID, &chMask);
00147         CS_WriteParameter(CS_EXT_PANID_ID, &extPanId);
00148 
00149         // Start network
00150         ZDO_StartNetworkReq(&networkParams);
00151         break;
00152       }
00153 
00154     // Node is in network
00155     case APP_IN_NETWORK_STATE:
00156 
00157       // Process task dependent on device type
00158       switch (appDeviceType)
00159       {
00160         case DEVICE_TYPE_COORDINATOR:
00161           appCoordTaskHandler();
00162           break;
00163 
00164         case DEVICE_TYPE_ROUTER:
00165           appRouterTaskHandler();
00166           break;
00167 
00168         case DEVICE_TYPE_END_DEVICE:
00169         default:
00170           break;
00171       }
00172 
00173     // Node is out of network
00174     case APP_NO_NETWORK_STATE:
00175       break;
00176 
00177     default:
00178       break;
00179   }
00180 }
00181 
00182 /********************************************************************
00183   Description: Delay after network start/join has fired
00184 
00185   Parameters: none.
00186 
00187   Returns: nothing.
00188 ********************************************************************/
00189 static void delayTimerFired(void)
00190 {
00191   SYS_PostTask(APL_TASK_ID);
00192 }
00193 
00194 /********************************************************************
00195   Description: ZDO_StartNetwork primitive confirmation was received.
00196 
00197   Parameters: confirmInfo - confirmation information
00198 
00199   Returns: nothing.
00200 ********************************************************************/
00201 static void ZDO_StartNetworkConf(ZDO_StartNetworkConf_t *confirmInfo)
00202 {
00203   if (ZDO_SUCCESS_STATUS == confirmInfo->status)
00204   {
00205     HAL_StopAppTimer(&startingNetworkTimer);
00206     BSP_OnLed(NETWORK_LED); // Indicate successful network join by turning LED on
00207 
00208     appState = APP_IN_NETWORK_STATE; // Switch state
00209 
00210     // Register endpoint
00211     CS_WriteParameter(CS_STACK_PROFILE_ID, &endpointParams.simpleDescriptor->AppProfileId);
00212     APS_RegisterEndpointReq(&endpointParams);
00213 
00214     // Configure and start delay timer
00215     delayTimer.interval = TIMER_DELAY_PERIOD;
00216     delayTimer.mode     = TIMER_ONE_SHOT_MODE;
00217     delayTimer.callback = delayTimerFired;
00218     HAL_StartAppTimer(&delayTimer);
00219   }
00220   else
00221   {
00222     SYS_PostTask(APL_TASK_ID);
00223   }
00224 }
00225 
00226 /********************************************************************
00227   Description: ZDO_MgmtNwkUpdateNotf primitive confirmation was received
00228 
00229   Parameters: nwkParams - updated network parameters
00230 
00231   Returns: nothing.
00232 ********************************************************************/
00233 void ZDO_MgmtNwkUpdateNotf(ZDO_MgmtNwkUpdateNotf_t *nwkParams)
00234 {
00235   // Network is lost/left
00236   if (ZDO_NETWORK_LOST_STATUS == nwkParams->status)
00237   {
00238     HAL_StartAppTimer(&startingNetworkTimer); // Start indication of network join process
00239     appState = APP_NETWORK_STARTING_STATE;    // In order to rejoin, switch application to network starting state
00240 
00241     SYS_PostTask(APL_TASK_ID);
00242   }
00243 }
00244 
00245 
00246 /********************************************************************
00247   Description: dummy wakeup event handler
00248 
00249   Parameters: none.
00250 
00251   Returns: nothing.
00252 ********************************************************************/
00253 void ZDO_WakeUpInd(void)
00254 {
00255 }
00256 
00257 /********************************************************************
00258   Description: dummy sleep event handler
00259 
00260   Parameters: none.
00261 
00262   Returns: nothing.
00263 ********************************************************************/
00264 void ZDO_SleepInd(void)
00265 {
00266 }
00267 
00268 // eof throughputTest.c

Generated on Tue Feb 17 16:44:56 2009 for BitCloud Stack Documentation by  doxygen 1.5.1-p1