int main( void )
{
    halInit();
    moduleInit();
    printf("\r\nWriting NV Items\r\n");
    result = moduleReset();
    if (result == MODULE_SUCCESS)
    {
        displaySysResetInd();  // Display the contents of the received SYS_RESET_IND message
    } else {
        printf("Module Reset ERROR 0x%02X\r\n", result);
    }
    debugConsoleIsr = &handleDebugConsoleInterrupt;   //call method handleDebugConsoleInterrupt() when a byte is received    
    HAL_ENABLE_INTERRUPTS();              //Enable Interrupts

    while (1)
    {
        uint8_t whichNvItem = getWhichNvItemToWrite();  
        if (whichNvItem != NO_CHARACTER_RECEIVED)
        {
            uint8_t nvItemSize = getNvItemSize(whichNvItem);
            printf("\r\nWriting to NV item %u, L%u:", whichNvItem, nvItemSize);    
            printHexBytes(dataToWrite, nvItemSize);
            result = sysNvWrite(whichNvItem, dataToWrite);
            if (result != MODULE_SUCCESS)
            {
                printf("sysNvWrite ERROR 0x%02X\r\n", result);
            }
        }
    }
}
Пример #2
0
int main( void )
{

    halInit();
    moduleInit();
    printf("\r\nResetting Module\r\n"); 
    HAL_ENABLE_INTERRUPTS();    
    moduleReset();
    while (1)
    {
        printf("Module Reset: ");
        result = moduleReset();
        if (result == MODULE_SUCCESS)
        {
            displaySysResetInd();  // Display the contents of the received SYS_RESET_IND message
        } else {
            printf("ERROR 0x%02X\r\n", result);
        }
        delayMs(3000);
    }
}
Пример #3
0
int main( void )
{
    halInit();
    moduleInit();    
    printf("\r\nResetting Module, then getting MAC Address\r\n");
    HAL_ENABLE_INTERRUPTS();
    
    result = moduleReset();
    if (result == MODULE_SUCCESS)
    {
        /* Display the contents of the received SYS_RESET_IND message */
        displaySysResetInd();  
    } else {
        printf("ERROR 0x%02X\r\n", result);
    }    
    
    while (1)
    {
        result = zbGetDeviceInfo(DIP_MAC_ADDRESS);
        if (result == MODULE_SUCCESS)
        {
            uint8_t* mac = zmBuf+SRSP_DIP_VALUE_FIELD;
            printf("MAC (as sent, LSB first):");
            printHexBytes(mac, 8);
            
            /* Note: the MAC address comes over the wire in reverse order (LSB first)
            So we swap the order of the bytes so we can display it correctly. */
            uint8_t temp[8];
            int i;
            for (i=0; i<8; i++)
            {
                temp[i] = mac[7-i];
            }
            printf("MAC (correct, MSB first):");
            printHexBytes(temp, 8);
            printf("\r\n");
        } else {
            printf("ERROR 0x%02X\r\n", result);
        }
        toggleLed(1);
        delayMs(1000);
    }
}
Пример #4
0
int main( void )
{
    halInit();
    moduleInit();  
    printf("\r\nResetting Radio, then getting Random Number\r\n");
    moduleReset();   
    while (1)
    {
        /* Get a random number from the module */
        result = sysRandom();
        if (result == MODULE_SUCCESS)                  
        {
            /* Random number is in zmBuf. Now we use a convenience macro to read result from zmBuf */
            uint16_t randomNumber = SYS_RANDOM_RESULT();    
            printf("Random Number = %u (0x%04X)\r\n", randomNumber, randomNumber);
        } else {
            printf("ERROR 0x%02X\r\n", result);
        }
        toggleLed(1);
        delayMs(1000);
    }
}
Пример #5
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

}
Пример #6
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
}