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
MBOOL 
Pass2NodeImpl::
onInit()
{
    FUNC_START;
    MBOOL ret = MFALSE;

    mpIspSyncCtrlHw = IspSyncControlHw::createInstance(getSensorIdx());
    if(!mpIspSyncCtrlHw)
    {
        MY_LOGE("create IspSyncControlHw failed");
        goto lbExit;
    }

    mlPostBufData.clear();

    if( !moduleInit() )
    {
        MY_LOGE("moduleInit() failed");
        goto lbExit;
    }

    ret = MTRUE;
lbExit:
    FUNC_END;
    return ret;
}
int main( void )
{
    halInit();
    moduleInit();    
    printf("\r\n****************************************************\r\n");    
    printf("Fragmentation Example - ROUTER - using AFZDO\r\n");
    buttonIsr = &handleButtonPress;    

#define MODULE_START_DELAY_IF_FAIL_MS 5000

    /* See basic communications examples for more information about module startup. */
    struct moduleConfiguration defaultConfiguration = DEFAULT_MODULE_CONFIGURATION_ROUTER;
    start: 
    while ((result = startModule(&defaultConfiguration, GENERIC_APPLICATION_CONFIGURATION)) != MODULE_SUCCESS)
    {
        printf("Module start unsuccessful. Error Code 0x%02X. Retrying...\r\n", result);
        delayMs(MODULE_START_DELAY_IF_FAIL_MS);
    }
    printf("On Network!\r\n");
    setLed(0);
    /* On network, display info about this network */ 
#ifdef DISPLAY_NETWORK_INFORMATION    //excluded to reduce code size
    displayNetworkConfigurationParameters();   
    displayDeviceInformation();
#endif 
    HAL_ENABLE_INTERRUPTS();

    /* Now the network is running - send a message to the coordinator every few seconds.*/
#define TEST_CLUSTER 0x77    

    /* Fill test message buffer with an incrementing counter */
    int i = 0;
    for (i=0; i<MESSAGE_LENGTH; i++)
    {
    	testMessage[i] = i;
    }
    printf("Sending the following message:\r\n");

    uint8_t counter = 0;
    while (1)
    {       
        printf("Sending Message #%u L%u to Short Address 0x0000 (Coordinator) ", counter++, MESSAGE_LENGTH);
        /* Send an extended length message to a short address */
        moduleResult_t result = afSendDataExtendedShort(DEFAULT_ENDPOINT, DEFAULT_ENDPOINT, 0, TEST_CLUSTER, testMessage, MESSAGE_LENGTH);  //a short message - coordinator will receive an AF_INCOMING_MSG_EXT
        if (result == MODULE_SUCCESS)
        {
            printf("Success\r\n");
        } else {
            printf("ERROR %i ", result);
#ifdef RESTART_AFTER_ZM_FAILURE
            printf("\r\nRestarting\r\n");
            goto start;
#else        
            printf("stopping\r\n");
            while(1);
#endif
        }
        delayMs(2000);  
    }   
}
int main( void )
{
    halInit();
    moduleInit();    
    printf("\r\n****************************************************\r\n");    
    printf("Secure Communications Example - ROUTER - using AFZDO\r\n");
    HAL_ENABLE_INTERRUPTS();

#define MODULE_START_DELAY_IF_FAIL_MS 5000

    struct moduleConfiguration defaultConfiguration = DEFAULT_MODULE_CONFIGURATION_ROUTER;
    defaultConfiguration.securityMode = SECURITY_MODE_PRECONFIGURED_KEYS;
    defaultConfiguration.securityKey = key;
    start:
    while ((result = startModule(&defaultConfiguration, GENERIC_APPLICATION_CONFIGURATION)) != MODULE_SUCCESS)
    {
        printf("Module start unsuccessful. Error Code 0x%02X. Retrying...\r\n", result);
        delayMs(MODULE_START_DELAY_IF_FAIL_MS);
    }

    printf("On Network!\r\n");
    setLed(0);

    /* On network, display info about this network */
#ifdef DISPLAY_NETWORK_INFORMATION     
    displayNetworkConfigurationParameters();
    displayDeviceInformation();
#endif  

    /* Now the network is running - send a message to the coordinator every few seconds.*/
#define TEST_CLUSTER 0x77    

    while (1)
    {
        printf("Sending Message %u  ", counter++);
        result = afSendData(DEFAULT_ENDPOINT,DEFAULT_ENDPOINT,0, TEST_CLUSTER, testMessage, 5);
        if (result == MODULE_SUCCESS)
        {
            printf("Success\r\n");
        } else {
            printf("ERROR %02X ", result);
#ifdef RESTART_AFTER_ZM_FAILURE
            printf("\r\nRestarting\r\n");
            goto start;
#else        
            printf("stopping\r\n");
            while(1);
#endif
        }
        toggleLed(1);
        delayMs(2000);
    }
}
int main( void )
{
    halInit();
    moduleInit();
    buttonIsr = &handleButtonPress;
    sysTickIsr = &sysTick;    
    printf("\r\n****************************************************\r\n");
    printf("Config Application Example - COORDINATOR\r\n");    
    clearLeds();    
    halRgbLedPwmInit();
    initSysTick();
    HAL_ENABLE_INTERRUPTS(); //NEW
    stateMachine();    //run the state machine
}
int main( void )
{
    halInit();
    moduleInit();
    printf("\r\n****************************************************\r\n");    
    printf("Zigbee Network Explorer\r\n");
    debugConsoleIsr = &handleDebugConsoleInterrupt;
    HAL_ENABLE_INTERRUPTS();
    clearLeds();
    
    /* Now the network is running - wait for any received messages from the ZM */
#ifdef VERBOSE_MESSAGE_DISPLAY    
    printAfIncomingMsgHeaderNames();
#endif
    
    stateMachine();
}
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);
    }
}
void WMTemplateRoiSelection::moduleMain()
{
    moduleInit();

    WLEMMCommand::SPtr emmIn;

    debugLog() << "Entering main loop";

    while( !m_shutdownFlag() )
    {
        // ---------- SHUTDOWNEVENT ----------
        if( m_shutdownFlag() )
        {
            break; // break mainLoop on shutdown
        }

        if( m_input->isEmpty() ) // continue processing if data is available
        {
            m_moduleState.wait(); // wait for events like input-data or properties changed
        }

        // receive data form the input-connector
        emmIn.reset();
        if( !m_input->isEmpty() )
        {
            emmIn = m_input->getData();
        }
        const bool dataValid = ( emmIn );

        // ---------- INPUTDATAUPDATEEVENT ----------
        if( dataValid ) // If there was an update on the input-connector
        {
            // The data is valid and we received an update. The data is not NULL but may be the same as in previous loops.
            debugLog() << "received data";

            process( emmIn );

            debugLog() << "finished processing";
        }
    }
}
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);
    }
}
int main( void )
{
    structInit();
    halInit();
    moduleInit();
    buttonIsr = &handleButtonPress;    
    printf("\r\n****************************************************\r\n");
    printf("Simple Application Example - COORDINATOR\r\n");
    
    routers[0].MAC_address[0] = 0x5E;
    routers[0].MAC_address[1] = 0xD2;
    routers[0].MAC_address[2] = 0x5D;
    routers[0].MAC_address[3] = 0x02;
    routers[0].MAC_address[4] = 0x00;
    routers[0].MAC_address[5] = 0x4B;
    routers[0].MAC_address[6] = 0x12;
    routers[0].MAC_address[7] = 0x00;
    
    routers[1].MAC_address[0] = 0xD3;
    routers[1].MAC_address[1] = 0xD3;
    routers[1].MAC_address[2] = 0x5D;
    routers[1].MAC_address[3] = 0x02;
    routers[1].MAC_address[4] = 0x00;
    routers[1].MAC_address[5] = 0x4B;
    routers[1].MAC_address[6] = 0x12;
    routers[1].MAC_address[7] = 0x00;
    
    HAL_ENABLE_INTERRUPTS();
    clearLeds();
    
    halRgbLedPwmInit();
    
    while (1) {
        stateMachine();    //run the state machine
        if (alarm_sounding == 1 && !alarm_silenced) {
          delayMs(2);
          toggleLed(0);
        }
    }
}
示例#11
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);
    }
}
int main( void )
{
    halInit();
    moduleInit();    
    HAL_DISABLE_INTERRUPTS();
    printf("\r\n****************************************************\r\n");    
    printf("Simple Application Example - END DEVICE\r\n");  
    uint16_t vlo = calibrateVlo();
    printf("VLO = %u Hz\r\n", vlo);   
    timerIsr = &handleTimer;  
    clearLeds();
    HAL_ENABLE_INTERRUPTS();
    
    /* Most of the of infoMessage are the same, so we can create most of the message ahead of time. */
    hdr.sequence = 0;  //this will be incremented each message
    hdr.version = INFO_MESSAGE_VERSION;
    hdr.flags = INFO_MESSAGE_FLAGS_NONE;
    
    initializeSensors();
    delayMs(100);
    stateMachine();
}
void WMHeadPositionCorrection::moduleMain()
{
    moduleInit();

    WLEMMCommand::SPtr cmdIn;
    while( !m_shutdownFlag() )
    {
        if( m_input->isEmpty() ) // continue processing if data is available
        {
            debugLog() << "Waiting for Events";
            m_moduleState.wait(); // wait for events like inputdata or properties changed
        }

        if( m_shutdownFlag() )
        {
            break; // break mainLoop on shutdown
        }

        if( m_propPosFile->changed( true ) )
        {
            m_hasRefPos = hdlPosFileChanged( m_propPosFile->get().string() );
        }

        cmdIn.reset();
        if( !m_input->isEmpty() )
        {
            cmdIn = m_input->getData();
        }
        const bool dataValid = ( cmdIn );
        if( dataValid )
        {
            process( cmdIn );
        }
    }

    viewCleanup();
}
int main( void )
{
    halInit();
    moduleInit();
    printf("\r\n****************************************************\r\n");
    printf("Packet Error Rate Tester - ROUTER\r\n");
    buttonIsr = &handleButtonPress;
    
#define MODULE_START_DELAY_IF_FAIL_MS 5000
    
    /* Use the default module configuration */
    struct moduleConfiguration defaultConfiguration = DEFAULT_MODULE_CONFIGURATION_ROUTER;
    
    /* Turn Off nwk status LED if on */
    clearLed(ON_NETWORK_LED);
    
    /* Loop until module starts */
    while ((result = expressStartModule(&defaultConfiguration, GENERIC_APPLICATION_CONFIGURATION, MODULE_REGION_NORTH_AMERICA)) != MODULE_SUCCESS)
    {
        /* Module startup failed; display error and blink LED */
        setLed(NETWORK_FAILURE_LED);                    
        printf("Module start unsuccessful. Error Code 0x%02X. Retrying...\r\n", result);
        delayMs(MODULE_START_DELAY_IF_FAIL_MS/2);                    
        clearLed(NETWORK_FAILURE_LED);
        delayMs(MODULE_START_DELAY_IF_FAIL_MS/2);
    }
    printf("On Network!\r\n");
    
    /* Indicate we got on the network */
    setLed(ON_NETWORK_LED); 
    
    /* On network, display info about this network */
#ifdef DISPLAY_NETWORK_INFORMATION     
    displayNetworkConfigurationParameters();                
    displayDeviceInformation();
#else
    displayBasicDeviceInformation();
#endif
    
    HAL_ENABLE_INTERRUPTS();
    
    /* Now the network is running - send messages to the Coordinator.*/    
#define TEST_CLUSTER 0x77
    
#define MESSAGE_HEADER_LENGTH    13
#define MESSAGE_LENGTH  (TEST_MESSAGE_PAYLOAD_LENGTH + MESSAGE_HEADER_LENGTH)
    /* Here we precompute zmBuf contents so that we don't have to do it in the loop. This is faster.
    This is the equivalent of afSendData(DEFAULT_ENDPOINT,DEFAULT_ENDPOINT,0, TEST_CLUSTER, testMessage, 10); */
    uint8_t testBuf[MESSAGE_LENGTH];
    testBuf[0] = MESSAGE_LENGTH;
    testBuf[1] = MSB(AF_DATA_REQUEST);
    testBuf[2] = LSB(AF_DATA_REQUEST);      
    
    testBuf[3] = 0; 
    testBuf[4] = 0;
    testBuf[5] = DEFAULT_ENDPOINT;
    testBuf[6] = DEFAULT_ENDPOINT;
    testBuf[7] = LSB(TEST_CLUSTER); 
    testBuf[8] = MSB(TEST_CLUSTER); 
    testBuf[9] = 0xFF;  // Sequence: we don't care
    testBuf[10] = AF_MAC_ACK; //Could also use AF_APS_ACK;
    testBuf[11] = DEFAULT_RADIUS;
    testBuf[12] = TEST_MESSAGE_PAYLOAD_LENGTH; // Datalength
    //memcpy(testBuf+MESSAGE_HEADER_LENGTH, testMessage, TEST_MESSAGE_PAYLOAD_LENGTH);
    //testBuf is now loaded with our test message.        
    
    printf("!!  Sending %u messages  !!\r\n", NUMBER_OF_PACKETS_TO_SEND);    
    
    while (1)
    {
    	uint16_t packetCounter;
        for (packetCounter = 0; packetCounter<NUMBER_OF_PACKETS_TO_SEND; packetCounter++)
        {
            /* Copy our message over to zmBuf because zmBuf gets overwritten when the AF_DATA_CONFIRM is received */
            memcpy(zmBuf, testBuf, MESSAGE_LENGTH);
            
            /* Now initialize the payload */
            int index;
            for (index = MESSAGE_HEADER_LENGTH; index < (TEST_MESSAGE_PAYLOAD_LENGTH + MESSAGE_HEADER_LENGTH); index++)
            {
                testBuf[index] = index;
            }

            /* Send the message to the Coordinator */
            result = sendMessage();       
            if (result != MODULE_SUCCESS)
            {
                printf("afSendData Error %02X; stopping\r\n", result);
                while (1);
            }        
            
            /* Now, wait for the AF_DATA_CONFIRM to verify that the message was successfully sent*/
            while (!(MODULE_HAS_MESSAGE_WAITING()));
            
            /* Retrieve the AF_DATA_CONFIRM message */
            getMessage();
            
            if (!(IS_AF_DATA_CONFIRM())) 
            {
                /* Stop if we receive a different message */
                printf("Error; stopped after packet %u", packetCounter);
            }        
            
            toggleLed(1); 
            /* If you want to slow down the rate of sending packets then add:
            delayMs(1);
            which will add a one mSec delay after each packet is sent. */
            
            if (((packetCounter % 100) == 0) && (packetCounter != 0))
            {
                printf("%u\r\n", packetCounter);
            }
        }
        printf("Done! Sent %u packets!\r\nPress button to start again\r\n", NUMBER_OF_PACKETS_TO_SEND);        
        
        /* Wait until a button is pressed, then send another 1000 */
        while (!(buttonIsPressed(ANY_BUTTON)));
    }
}