⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prodtestcoord.c

📁 wireless jennic application note
💻 C
📖 第 1 页 / 共 4 页
字号:
PUBLIC void JZA_vAppDefineTasks(void)
{
}

/****************************************************************************
 *
 * NAME: JZA_eAfKvpObject
 *
 * DESCRIPTION:
 * Receives incoming KVP data frames
 *
 * PARAMETERS:      Name                RW  Usage
 *                  eAddrMode           R   Address mode of incoming frame
 *                  u16AddrSrc          R   Network address of source node
 *                  u8SrcEP             R   Endpoint address of source node
 *                  u8LQI               R   Link Quality Indication
 *                  u8DstEP             R   Destination endpoint address
 *                  u8ClusterId         R   Cluster ID of incoming frame
 *                  *pu8ClusterIDRsp    R   Pointer to cluster ID of response frame
 *                  *puTransactionInd   R   Pointer to incoming frame
 *                  *puTransactionRsp   R   Pointer to response frame
 *
 * RETURNS:
 * TRUE for stack to automatically generate KVP response frames when appropriate
 * FALSE otherwise
 *
 ****************************************************************************/
PUBLIC bool_t JZA_bAfKvpObject( APS_Addrmode_e          eAddrMode,
                                uint16                  u16AddrSrc,
                                uint8                   u8SrcEP,
                                uint8                   u8LQI,
                                uint8                   u8DstEP,
                                uint8                   u8ClusterId,
                                uint8                   *pu8ClusterIDRsp,
                                AF_Transaction_s        *puTransactionInd,
                                AF_Transaction_s        *puTransactionRsp)
{
    tsNodeData *psNodeData;
    int i;
    uint64 u64DeviceAddr = 0;
    bool_t boFound;
    uint8   u8Length;
    uint8   *pu8Afdu;

    u8Length = puTransactionInd->uFrame.sKvp.uAttributeData.CharacterString.u8CharacterCount;
    pu8Afdu = puTransactionInd->uFrame.sKvp.uAttributeData.CharacterString.au8CharacterData;

    /* Perform validity checking */
    if ((eAddrMode != APS_ADDRMODE_SHORT) || (u8DstEP != 0x40))
    {
        puTransactionRsp->uFrame.sKvp.eErrorCode = KVP_INVALID_ENDPOINT;
        return TRUE;
    }

    if (   (puTransactionInd->uFrame.sKvp.eCommandTypeID != SET)
        && (puTransactionInd->uFrame.sKvp.eCommandTypeID != SET_ACKNOWLEDGMENT))
    {
        puTransactionRsp->uFrame.sKvp.eErrorCode = KVP_INVALID_COMMAND_TYPE;
        return TRUE;
    }

    pu8Afdu++;

    if(puTransactionInd->uFrame.sKvp.u16AttributeID == DAP_ATTR_SENSOR_DATA)
    {
        /* Search for address in list */
        boFound = FALSE;

        for (i = 0; i < 8; i++)
        {
            u64DeviceAddr = u64DeviceAddr << 8;
            u64DeviceAddr |= *pu8Afdu++;
        }

        i = 0;

        while (i < sDemoData.sNode.u8AssociatedNodes)
        {
            if (sDemoData.sNode.asNodeData[i].u64ExtAdr == u64DeviceAddr)
            {
                /* Update short address in case node has joined another parent
                   since last time it transmitted a frame */
                sDemoData.sNode.asNodeData[i].u16ShortAdr = u16AddrSrc;
                boFound = TRUE;
                break;
            }
            i++;
        }

        if (boFound == FALSE)
        {
            /* Source has not been seen before */
            if (i < DEMO_ENDPOINTS)
            {
                /* Add device to list */
                sDemoData.sNode.u8AssociatedNodes++;
                sDemoData.sNode.asNodeData[i].u64ExtAdr = u64DeviceAddr;
                sDemoData.sNode.asNodeData[i].u16ShortAdr = u16AddrSrc;

                if (sDemoData.sSystem.eState == E_STATE_SPLASH)
                {
                    /* First device seen, so move away from splash screen */
                    sDemoData.sSystem.eState = E_STATE_NETWORK;
                }

                if (sDemoData.sSystem.eState == E_STATE_NETWORK)
                {
                    vBuildNetworkScreen();
                }

                if (sDemoData.sTestData.bTestMode == TRUE)
                {
                    acEndpointAssociated[3] = '0' + i;
                    vSendOnUart(acEndpointAssociated);

                    if (i == (TEST_ENDPOINTS - 1))
                    {
                        /* All nodes are associated so start timer for sync loss */
                        int j;

                        for (j = 0; j < TEST_ENDPOINTS; j++)
                        {
                            sDemoData.sTestData.au8SyncLoss[j] = 0;
                            sDemoData.sNode.asNodeData[j].u8FramesMissed = 0;
                        }
                        sDemoData.sTestData.u8Count = TEST_SYNC_COUNT;
                    }
                }
            }
            else
            {
                /* Return if device cannot be supported due to lack of space */
                puTransactionRsp->uFrame.sKvp.eErrorCode = KVP_INVALID_COMMAND_TYPE;
                return KVP_SUCCESS;
            }
        }

        /* Read received data into node data structure */
        psNodeData = &sDemoData.sNode.asNodeData[i];
        psNodeData->u8FramesMissed = 0;
        psNodeData->asNodeElementData[E_SENSOR_ALS].u8NowValue  = *pu8Afdu++;
        psNodeData->asNodeElementData[E_SENSOR_TEMP].u8NowValue = *pu8Afdu++;
        psNodeData->asNodeElementData[E_SENSOR_HTS].u8NowValue  = *pu8Afdu++;
        psNodeData->u8SwitchOn = *pu8Afdu++;
        vLedControl(i, psNodeData->u8SwitchOn);
    }

    puTransactionRsp->uFrame.sKvp.eErrorCode = KVP_INVALID_COMMAND_TYPE;
    return KVP_SUCCESS;
}

/****************************************************************************
 *
 * NAME: JZA_vAfKvpResponse
 *
 * DESCRIPTION:
 * Used to send response to incoming KVP frame
 *
 * PARAMETERS:      Name                RW  Usage
 *                  eAddrMode           R   Address mode of incoming frame
 *                  u16AddrSrc          R   Network address of source node
 *                  u8SrcEP             R   Endpoint address of source node
 *                  u8LQI               R   Link Quality Indication
 *                  u8DstEP             R   Destination endpoint address
 *                  u8ClusterId         R   Cluster ID of incoming frame
 *                  *puTransactionInd   R   Pointer to incoming frame
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PUBLIC void JZA_vAfKvpResponse(APS_Addrmode_e           eAddrMode,
                                uint16                  u16AddrSrc,
                                uint8                   u8SrcEP,
                                uint8                   u8LQI,
                                uint8                   u8DstEP,
                                uint8                   u8ClusterID,
                                AF_Transaction_s        *puTransactionInd)
{
}

/****************************************************************************
 *
 * NAME: JZA_pu8AfMsgObject
 *
 * DESCRIPTION:
 * Receives incoming MSG data frames.
 *
 * PARAMETERS:      Name                    RW  Usage
 *                  eAddrMode           R   Address mode of incoming frame
 *                  u16AddrSrc          R   Network address of source node
 *                  u8SrcEP             R   Endpoint address of source node
 *                  u8LQI               R   Link Quality Indication
 *                  u8DstEP             R   Destination endpoint address
 *                  u8ClusterId         R   Cluster ID of incoming frame
 *                  *pu8ClusterIDRsp    R   Pointer to cluster ID of response frame
 *                  *puTransactionInd   R   Pointer to incoming frame
 *                  *puTransactionRsp   R   Pointer to response frame
 * RETURNS:
 * FALSE
 *
 ****************************************************************************/
PUBLIC bool_t JZA_bAfMsgObject(APS_Addrmode_e       eAddrMode,
                                uint16              u16AddrSrc,
                                uint8               u8SrcEP,
                                uint8               u8LQI,
                                uint8               u8DstEP,
                                uint8               u8ClusterID,
                                uint8               *pu8ClusterIDRsp,
                                AF_Transaction_s    *puTransactionInd,
                                AF_Transaction_s    *puTransactionRsp)
{
    return FALSE;
}

/****************************************************************************
 *
 * NAME: JZA_vStackEvent
 *
 * DESCRIPTION:
 * Called when a miscellaneous stack event occurs.
 *
 * PARAMETERS:      Name          RW  Usage
 *                  eEventId      R   Event enumeration
 *                  puStackEvent  R   Event information
 *
 * RETURNS:
 * NULL
 *
 ****************************************************************************/
PUBLIC void JZA_vStackEvent(teJZS_EventIdentifier eEventId,
                            tuJZS_StackEvent *puStackEvent)
{
    if (eEventId == JZS_EVENT_NWK_STARTED)
    {
        vAddDesc();
    }
}

/****************************************************************************
 *
 * NAME: JZA_vZdpResponse
 *
 * DESCRIPTION:
 * Called when a ZDP response frame has been received. In this case no action
 * is taken as no ZDP responses are anticipated.
 *
 * PARAMETERS:      Name           RW  Usage
 *                  u8Type         R   ZDP response type
 *                  pu8Payload     R   Payload buffer
 *                  u8PayloadLen   R   Length of payload
 *
 ****************************************************************************/
PUBLIC void JZA_vZdpResponse(uint8 u8Type, uint8 u8LQI, uint8 *pu8Payload,
                             uint8 u8PayloadLen)
{
}

/****************************************************************************/
/***        Local Functions                                               ***/
/****************************************************************************/
/****************************************************************************
 *
 * NAME: vInitDemoSystem
 *
 * DESCRIPTION:
 * Initialises Zigbee stack and hardware. Final action is to start BOS, from
 * which there is no return. Subsequent application actions occur in the
 * functions defined above.
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vInitDemoSystem(void)
{
    /* Initialise Zigbee stack */
    sDemoData.sSystem.u32ZigbeeStackVersion = JZS_u32InitSystem(TRUE);

    /* Set up buttons and LEDs */
    vLedControl(0, FALSE);
    vLedControl(1, FALSE);
    vLedControl(2, FALSE);
    vLedControl(3, FALSE);
    vLedInitFfd();
    vButtonInitFfd();

    /* Initialise UART0 for communication */
    vAHI_UartEnable(0);
    vAHI_UartReset(0, TRUE, TRUE);
    vAHI_UartSetClockDivisor(0, E_AHI_UART_RATE_38400);
    vAHI_UartReset(0, FALSE, FALSE);
    vAHI_UartSetInterrupt(0, FALSE, FALSE, FALSE, TRUE, 1);

    vALSreset();
    vHTSreset();

    /* Start ambient light sensor now: it automatically keeps re-sampling after this */
    vALSstartReadChannel(0);

    /* Calibrate wake timer */
    sDemoData.sSystem.u32CalibratedTimeout = BLOCK_TIME_IN_32K_PERIODS * 10000 / u32AHI_WakeTimerCalibrate();

    vSendOnUart(acTestStart);

    /* Enable timer to use for sequencing */
    vAHI_WakeTimerEnable(E_AHI_WAKE_TIMER_1, TRUE);

    /* Initialise software elements */
    vInitCoord();

    /* Set up LCD panel and splash screen */
    vLcdResetDefault();
    vLcdWriteBitmap((tsBitmap *)&sJennicLogo, 0, 0);
    vLcdWriteText("Zigbee Home Sensor Demo", 5, 0);
    vLcdWriteText("Ch", 7, 0);
    vLcdWriteText("\\", 7, 47);
    vLcdWriteText("]", 7, 74);
    vLcdWriteText("Done", 7, 103);
    vUpdateSplashScreen();

    /* Start BOS */
    bBosRun(TRUE);
}

/****************************************************************************
 *
 * NAME: vInitCoord
 *
 * DESCRIPTION:
 * Initialises software structures and variables. Endpoint data is reset and
 * the GUI is set to the default condition.
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vInitCoord(void)
{
    tsNodeData        *psNodeData;
    tsNodeElementData *psNodeElementData;
    uint8             *pu8GraphData;
    int                i, j, k;

    /* Initialise node data */
    for (i = 0; i < DEMO_ENDPOINTS; i++)
    {
        psNodeData = &sDemoData.sNode.asNodeData[i];

        /* Set label */
        for (j = 0; j < DEMO_SENSOR_LIST_LEN; j++)
        {
            psNodeElementData = &psNodeData->asNodeElementData[j];

            /* Clear alarms and values */
            psNodeElementData->u8NowValue = 0;

            /* Clear history list */
            pu8GraphData = psNodeElementData->au8GraphData;
            for (k = 0; k < DEMO_HISTORY_LEN; k++)
            {
                pu8GraphData[k] = 0;
            }
        }
    }
    sDemoData.sNode.u8AssociatedNodes = 0;
    sDemoData.sTestData.bSensorsTested = TRUE; /* Sensor testing not complete yet, but assume it is */
    sDemoData.sTestData.u8Count = 255; /* Sensor board sync test count: 255 to disable */
    sDemoData.sTestData.u8CommandDigit = 0; /* Command string input digit */
    sDemoData.sTestData.bTestMode = FALSE; /* Test mode only entered if correct string received */

    /* Initialise GUI state */
    sDemoData.sGui.eCurrentSensor = E_SENSOR_ALS;
    sDemoData.sGui.u8CurrentNode = 0;
    sDemoData.sGui.u8GraphPos = 0;

    sDemoData.sQueue.u8ReadPtr = 0;
    sDemoData.sQueue.u8WritePtr = 0;

    sDemoData.sSystem.u8Channel = CHANNEL_DEFAULT;

    /* Set simple scheduler to perform no activity */
    sDemoData.sSystem.u8TimeBlock = MAX_BLOCKS;

    /* Change to splash screen mode */
    sDemoData.sSystem.eState = E_STATE_SPLASH;

    /* Set current key state */
    sDemoData.sGui.u8Keys = 0;

    vSetTimer();
}

/****************************************************************************
 *
 * NAME: vSetTimer
 *
 * DESCRIPTION:
 * Sets wake-up timer 0 for a 50ms time-out. Assumes that timer was
 * previously enabled.
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vSetTimer(void)
{
    /* Set timer for next block */
    vAHI_WakeTimerStart(E_AHI_WAKE_TIMER_1, sDemoData.sSystem.u32CalibratedTimeout);
}

/****************************************************************************
 *
 * NAME: vProcessCurrentTimeBlock
 *
 * DESCRIPTION:
 * Operates a simple state machine. Called 20 times per second, this performs
 * several tasks over a 1 second period, with the time split into 50ms blocks.
 * In one block it updates the display, in another it starts a reading from
 * the temperature, in another it reads the temperature, etc.
 *
 * PARAMETERS:      Name            RW  Usage
 *                  u8TimeBlock     R   Current time block, 0-19
 *
 * RETURNS:
 * void
 *
 * NOTES:
 * A value greater than 19 may be used for u8TimeBlock, to ensure that the
 * simple state machine remains idle.
 *
 ****************************************************************************/
PRIVATE void vProcessCurrentTimeBlock(uint8 u8TimeBlock)
{
    uint8 u8LocalSensor;

    /* Process current block scheduled activity */
    switch (u8TimeBlock)
    {
    case BLOCK_UPDATE:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -