Exemplo n.º 1
0
/** Configures the ZNP to only join the specified channel.
Wrapper for setChannelMask if only one channel is desired.
@param channel must be 11..26, inclusive. If set to 0 then ZNP will scan ALL CHANNELS
@post znpResult contains the error code, or ZNP_SUCCESS if success.
*/
void setChannel(unsigned char channel)
{
    if ((!IS_VALID_CHANNEL(channel)) && (channel != 0x00))
    {
        znpResult = -10;
        return;
    }
    unsigned long channelMask = 1;
    setChannelMask((channel == 0) ? ANY_CHANNEL :(channelMask << channel));  //will set znpResult on success/fail
}
Exemplo n.º 2
0
/**
Start the Module and join a network, using the AF/ZDO interface. Reads RF Operating Region (US/EU) from GPIO.
@param moduleConfiguration the settings to use to start the module
@param applicationConfiguration the settings to use to start the Zigbee Application
@see struct moduleConfiguration in module_utilities.h for information about each field of the moduleConfiguration
@see struct applicationConfiguration in application_configuration.h for information about each field of the applicationConfiguration
@see module.c for more information about each of these steps.
*/
moduleResult_t startModule(const struct moduleConfiguration* mc, const struct applicationConfiguration* ac)
{
	printf("Module Startup\r\n");
    /* Initialize the Module */
    RETURN_RESULT_IF_FAIL(moduleReset(), METHOD_START_MODULE);
    /* Clear out any old network or state information (if requested) */
    RETURN_RESULT_IF_FAIL(setStartupOptions(mc->startupOptions), METHOD_START_MODULE);   

/* This section is for reading Operating region from GPIO pins - omit if using different method */
    /* First, configure GPIOs as inputs: */
    RETURN_RESULT_IF_FAIL(sysGpio(GPIO_SET_DIRECTION , GPIO_DIRECTION_ALL_INPUTS), METHOD_START_MODULE);    
    RETURN_RESULT_IF_FAIL(sysGpio(GPIO_SET_INPUT_MODE , GPIO_INPUT_MODE_ALL_PULL_UPS), METHOD_START_MODULE); 
    /* Now, read GPIO inputs 0 & 1: */
    RETURN_RESULT_IF_FAIL(sysGpio(GPIO_READ, (GPIO_0 | GPIO_1)), METHOD_START_MODULE);
    /* The operating region (US vs. EU etc.) is based on DIP Switch settings, read from GPIO 0 & 1 */
    uint16_t moduleRegion = zmBuf[SYS_GPIO_READ_RESULT_FIELD];
    
/*** Done reading GPIO inputs. If application needs them as outputs then configure accordingly ***/
    
    /* Reset the Module to apply the changes we just set */
    RETURN_RESULT_IF_FAIL(moduleReset(), METHOD_START_MODULE);
    /* Read the productId - this indicates the model of module used. */
    uint8_t productId = zmBuf[SYS_RESET_IND_PRODUCTID_FIELD]; 
    /* If this is not valid (bad firmware) then stop */
    RETURN_RESULT_IF_EXPRESSION_TRUE((productId < MINIMUM_BUILD_ID), METHOD_START_MODULE,
                                     ZM_INVALID_MODULE_CONFIGURATION);       
    /* Configure the module's RF output */
    setModuleRfPower(productId, moduleRegion);
    /* Set any end device options */
    if (mc->deviceType == END_DEVICE)
	    RETURN_RESULT_IF_FAIL(setPollRate(mc->endDevicePollRate), METHOD_START_MODULE);
    /* Configure which RF Channels to use. If none set then this will default to 11. */
    RETURN_RESULT_IF_FAIL(setZigbeeDeviceType(mc->deviceType), METHOD_START_MODULE);     // Set Zigbee Device Type
    RETURN_RESULT_IF_FAIL(setChannelMask(mc->channelMask), METHOD_START_MODULE);
    RETURN_RESULT_IF_FAIL(setPanId(mc->panId), METHOD_START_MODULE);
    RETURN_RESULT_IF_FAIL(setCallbacks(CALLBACKS_ENABLED), METHOD_START_MODULE);
    
	                                                    // Note: ZCD_NV_SECURITY_MODE defaults to 01
	  if (mc->securityMode != SECURITY_MODE_OFF)        // Note: If a coordinator has ZCD_NV_SECURITY_MODE = 00, router must have ZCD_NV_SECURITY_MODE = 01 or else they won't communicate
	  {
	      RETURN_RESULT_IF_FAIL(setSecurityMode(mc->securityMode), METHOD_START_MODULE);
	      RETURN_RESULT_IF_FAIL(setSecurityKey(mc->securityKey), METHOD_START_MODULE);
	  }

	  if (ac == GENERIC_APPLICATION_CONFIGURATION)	  //TODO: use custom applicationFramework if this isn't null:
	  {
	    RETURN_RESULT_IF_FAIL(afRegisterGenericApplication(), METHOD_START_MODULE);    // Configure the Module for our application
	  } else {
	    printf("Custom Application Frameworks not supported\r\n");
	    return INVALID_PARAMETER;
	  }
	  RETURN_RESULT_IF_FAIL(zdoStartApplication(), METHOD_START_MODULE);		// Start your engines

	  /* Wait until this device has joined a network. Device State will change to DEV_ROUTER,
      DEV_END_DEVICE, or DEV_COORD to indicate that the device has correctly joined a network. */

	#ifdef ZDO_STATE_CHANGE_IND_HANDLED_BY_APPLICATION  //if you're handling this in your application instead...
	  return MODULE_SUCCESS;
	#else
	#define TEN_SECONDS 10000
	#define FIFTEEN_SECONDS 15000
	#define START_TIMEOUT FIFTEEN_SECONDS
	  RETURN_RESULT(waitForDeviceState(getDeviceStateForDeviceType(mc->deviceType), START_TIMEOUT), METHOD_START_MODULE);
	#endif

}
Exemplo n.º 3
0
/**
Starts module using an operating region as a parameter. This does NOT read the GPIO pin to set the region.
@param mc the module configuration - what RF channel, which PAN ID, etc. These options are used in
this expressStartModule function as arguments to the various functions.
@param ac the Zigbee application configuration - which endpoint to use and other global settings. 
If not using GENERIC_APPLICATION_CONFIGURATION then you must #define the compilation option 
SUPPORT_CUSTOM_APPLICATION_CONFIGURATION. Normally this option is NOT defined to reduce code size.
@param moduleRegion - which region of the world to use to ensure FCC/ETSI compliance.
*/
moduleResult_t expressStartModule(const struct moduleConfiguration* mc, const struct applicationConfiguration* ac, const uint8_t moduleRegion)
{
    printf("Express Startup ");
    
    /* Initialize the Module */
    RETURN_RESULT_IF_FAIL(moduleReset(), METHOD_EXPRESS_START_MODULE);
    
    /* Clear out any old network or state information (if requested) */
    printf("Startup Options 0x%02X\r\n", mc->startupOptions);
    RETURN_RESULT_IF_FAIL(setStartupOptions(mc->startupOptions), METHOD_EXPRESS_START_MODULE);

    /* Reset the Module to apply the changes we just set */
    RETURN_RESULT_IF_FAIL(moduleReset(), METHOD_EXPRESS_START_MODULE);
    
    /* Read the productId - this indicates the model of module used. */
    uint8_t productId = zmBuf[SYS_RESET_IND_PRODUCTID_FIELD]; 
    
    /* If this is not valid (bad firmware) then stop */
    RETURN_RESULT_IF_EXPRESSION_TRUE((productId < MINIMUM_BUILD_ID), METHOD_EXPRESS_START_MODULE, ZM_INVALID_MODULE_CONFIGURATION); 
    
    /* Configure the module's RF output */ 
    setModuleRfPower(productId, moduleRegion);
    
    /* Set any end device options */
    if (mc->deviceType == END_DEVICE)
    {
	    RETURN_RESULT_IF_FAIL(setPollRate(mc->endDevicePollRate), METHOD_EXPRESS_START_MODULE);
    }
    /* Override for testing low power operation - referenced in Basic Comms ED example*/
#ifdef DISABLE_END_DEVICE_POLLING
    RETURN_RESULT_IF_FAIL(setPollRate(0), METHOD_EXPRESS_START_MODULE);
#endif
    
    /* Configure the Zigbee Device Type (Coordinator, Router, End Device */
    RETURN_RESULT_IF_FAIL(setZigbeeDeviceType(mc->deviceType), METHOD_EXPRESS_START_MODULE);

    /* Configure which RF Channels to use. If none set then this will default to a default set. */
    RETURN_RESULT_IF_FAIL(setChannelMask(mc->channelMask), METHOD_EXPRESS_START_MODULE);
    
    /* Set the PAN ID, if you want to restrict the module to only a particular PAN ID. */
    RETURN_RESULT_IF_FAIL(setPanId(mc->panId), METHOD_EXPRESS_START_MODULE);
    RETURN_RESULT_IF_FAIL(setCallbacks(CALLBACKS_ENABLED), METHOD_EXPRESS_START_MODULE);
    
    /* Set security mode and security key if required. Note: If a coordinator has 
    ZCD_NV_SECURITY_MODE = 00 then router must have ZCD_NV_SECURITY_MODE = 01 or else they won't communicate */
    if (mc->securityMode != SECURITY_MODE_OFF)        
    {
    	RETURN_RESULT_IF_FAIL(setSecurityMode(mc->securityMode), METHOD_EXPRESS_START_MODULE);
    	RETURN_RESULT_IF_FAIL(setSecurityKey(mc->securityKey), METHOD_EXPRESS_START_MODULE);
    }

#ifdef SUPPORT_CUSTOM_APPLICATION_CONFIGURATION    
    if (ac == GENERIC_APPLICATION_CONFIGURATION)
    {
    RETURN_RESULT_IF_FAIL(afRegisterGenericApplication(), METHOD_EXPRESS_START_MODULE);    // Configure the Module for our application
    } else {
    RETURN_RESULT_IF_FAIL(afRegisterApplication(ac), METHOD_EXPRESS_START_MODULE);
    }
#else    
    if (ac == GENERIC_APPLICATION_CONFIGURATION)
    {
    RETURN_RESULT_IF_FAIL(afRegisterGenericApplication(), METHOD_EXPRESS_START_MODULE);    // Configure the Module for our application
    } else {
        /* Note: to use a custom application configuration, you must #define SUPPORT_CUSTOM_APPLICATION_CONFIGURATION. */
    return INVALID_PARAMETER;
    }    
#endif
    
    /* Note: you can register more than one Zigbee endpoint; just call afRegisterApplication() here
    for the next endpoint */
    
    /* Start the module with the registered application configuration */
    RETURN_RESULT_IF_FAIL(zdoStartApplication(), METHOD_EXPRESS_START_MODULE);

	  /* Wait until this device has joined a network. Device State will change to DEV_ROUTER,
      DEV_END_DEVICE, or DEV_COORD to indicate that the device has correctly joined a network. */

	#ifdef ZDO_STATE_CHANGE_IND_HANDLED_BY_APPLICATION  //if you're handling this in your application instead...
	  return MODULE_SUCCESS;
	#else
	#define TEN_SECONDS 10000
	#define FIFTEEN_SECONDS 15000
	  RETURN_RESULT(waitForDeviceState(getDeviceStateForDeviceType(mc->deviceType), FIFTEEN_SECONDS), METHOD_EXPRESS_START_MODULE);
	#endif
}