TI 工程师,你好
使用Z-Stack_Linux_Gateway网关,帮定了调光器和ZLL/HA灯,调光器可以控制灯的开关状态,但调不了光,看看可能是什么问题?
/**************************************************************************************************
Filename: zcl_samplesw.c
Revised: $Date: 2014-06-03 16:29:28 -0700 (Tue, 03 Jun 2014) $
Revision: $Revision: 38778 $
Description: Zigbee Cluster Library – sample device application.
Copyright 2006-2013 Texas Instruments Incorporated. All rights reserved.
IMPORTANT: Your use of this Software is limited to those specific rights
granted under the terms of a software license agreement between the user
who downloaded the software, his/her employer (which must be your employer)
and Texas Instruments Incorporated (the "License"). You may not use this
Software unless you agree to abide by the terms of the License. The License
limits your use, and you acknowledge, that the Software may not be modified,
copied or distributed unless embedded on a Texas Instruments microcontroller
or used solely and exclusively in conjunction with a Texas Instruments radio
frequency transceiver, which is integrated into your product. Other than for
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
works of, modify, distribute, perform, display or sell this Software and/or
its documentation for any purpose.
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
PROVIDED 揂S IS?WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
Should you have any questions regarding your right to use this Software,
contact Texas Instruments Incorporated at www.TI.com.
**************************************************************************************************/
/*********************************************************************
This device will be like an On/Off Switch device. This application
is not intended to be a On/Off Switch device, but will use the device
description to implement this sample code.
—————————————-
Main:
– SW1: Toggle remote light
– SW2: Invoke EZMode
– SW4: Enable/Disable Permit Join
– SW5: Go to Help screen
—————————————-
*********************************************************************/
/*********************************************************************
* INCLUDES
*/
#include "ZComDef.h"
#include "OSAL.h"
#include "AF.h"
#include "ZDApp.h"
#include "ZDObject.h"
#include "ZDProfile.h"
#include "MT_SYS.h"
#include "zcl.h"
#include "zcl_general.h"
#include "zcl_ha.h"
#include "zcl_samplesw.h"
#include "zcl_ezmode.h"
#include "onboard.h"
/* HAL */
#include "hal_lcd.h"
#include "hal_led.h"
#include "hal_key.h"
#if defined (OTA_CLIENT) && (OTA_CLIENT == TRUE)
#include "zcl_ota.h"
#include "hal_ota.h"
#endif
/*********************************************************************
* MACROS
*/
/*********************************************************************
* CONSTANTS
*/
/*********************************************************************
* TYPEDEFS
*/
/*********************************************************************
* GLOBAL VARIABLES
*/
byte zclSampleSw_TaskID;
uint8 zclSampleSwSeqNum;
uint8 zclSampleSw_OnOffSwitchType = ON_OFF_SWITCH_TYPE_TOGGLE;
uint8 zclSampleSw_OnOffSwitchActions = ON_OFF_SWITCH_ACTIONS_2; // Toggle -> Toggle
/*********************************************************************
* GLOBAL FUNCTIONS
*/
/*********************************************************************
* LOCAL VARIABLES
*/
#ifdef ZCL_ON_OFF
afAddrType_t zclSampleSw_DstAddr;
#endif
#ifdef ZCL_EZMODE
static void zclSampleSw_ProcessZDOMsgs( zdoIncomingMsg_t *pMsg );
static void zclSampleSw_EZModeCB( zlcEZMode_State_t state, zclEZMode_CBData_t *pData );
static const zclEZMode_RegisterData_t zclSampleSw_RegisterEZModeData =
{
&zclSampleSw_TaskID,
SAMPLESW_EZMODE_NEXTSTATE_EVT,
SAMPLESW_EZMODE_TIMEOUT_EVT,
&zclSampleSwSeqNum,
zclSampleSw_EZModeCB
};
// NOT ZLC_EZMODE, Use EndDeviceBind
#else
static cId_t bindingOutClusters[] =
{
ZCL_CLUSTER_ID_GEN_ON_OFF
};
#define ZCLSAMPLESW_BINDINGLIST (sizeof(bindingOutClusters)/sizeof(bindingOutClusters[0]))
#endif // ZLC_EZMODE
// Endpoint to allow SYS_APP_MSGs
static endPointDesc_t sampleSw_TestEp =
{
SAMPLESW_ENDPOINT, // endpoint
&zclSampleSw_TaskID,
(SimpleDescriptionFormat_t *)NULL, // No Simple description for this test endpoint
(afNetworkLatencyReq_t)0 // No Network Latency req
};
uint8 giSwScreenMode = SW_MAINMODE; // display the main screen mode first
static uint8 aProcessCmd[] = { 1, 0, 0, 0 }; // used for reset command, { length + cmd0 + cmd1 + data }
uint8 gPermitDuration = 0; // permit joining default to disabled
devStates_t zclSampleSw_NwkState = DEV_INIT;
#if defined (OTA_CLIENT) && (OTA_CLIENT == TRUE)
#define DEVICE_POLL_RATE 8000 // Poll rate for end device
#endif
/*********************************************************************
* LOCAL FUNCTIONS
*/
static void zclSampleSw_HandleKeys( byte shift, byte keys );
static void zclSampleSw_BasicResetCB( void );
static void zclSampleSw_IdentifyCB( zclIdentify_t *pCmd );
static void zclSampleSw_IdentifyQueryRspCB( zclIdentifyQueryRsp_t *pRsp );
static void zclSampleSw_ProcessIdentifyTimeChange( void );
// app display functions
void zclSampleSw_LcdDisplayUpdate(void);
void zclSampleSw_LcdDisplayMainMode(void);
void zclSampleSw_LcdDisplayHelpMode(void);
// Functions to process ZCL Foundation incoming Command/Response messages
static void zclSampleSw_ProcessIncomingMsg( zclIncomingMsg_t *msg );
#ifdef ZCL_READ
static uint8 zclSampleSw_ProcessInReadRspCmd( zclIncomingMsg_t *pInMsg );
#endif
#ifdef ZCL_WRITE
static uint8 zclSampleSw_ProcessInWriteRspCmd( zclIncomingMsg_t *pInMsg );
#endif
static uint8 zclSampleSw_ProcessInDefaultRspCmd( zclIncomingMsg_t *pInMsg );
#ifdef ZCL_DISCOVER
static uint8 zclSampleSw_ProcessInDiscCmdsRspCmd( zclIncomingMsg_t *pInMsg );
static uint8 zclSampleSw_ProcessInDiscAttrsRspCmd( zclIncomingMsg_t *pInMsg );
static uint8 zclSampleSw_ProcessInDiscAttrsExtRspCmd( zclIncomingMsg_t *pInMsg );
#endif
#if defined (OTA_CLIENT) && (OTA_CLIENT == TRUE)
static void zclSampleSw_ProcessOTAMsgs( zclOTA_CallbackMsg_t* pMsg );
#endif
/*********************************************************************
* ZCL General Profile Callback table
*/
static zclGeneral_AppCallbacks_t zclSampleSw_CmdCallbacks =
{
zclSampleSw_BasicResetCB, // Basic Cluster Reset command
zclSampleSw_IdentifyCB, // Identify command
#ifdef ZCL_EZMODE
NULL, // Identify EZ-Mode Invoke command
NULL, // Identify Update Commission State command
#endif
NULL, // Identify Trigger Effect command
zclSampleSw_IdentifyQueryRspCB, // Identify Query Response command
NULL, // On/Off cluster commands
NULL, // On/Off cluster enhanced command Off with Effect
NULL, // On/Off cluster enhanced command On with Recall Global Scene
NULL, // On/Off cluster enhanced command On with Timed Off
#ifdef ZCL_LEVEL_CTRL
NULL, // Level Control Move to Level command
NULL, // Level Control Move command
NULL, // Level Control Step command
NULL, // Level Control Stop command
#endif
#ifdef ZCL_GROUPS
NULL, // Group Response commands
#endif
#ifdef ZCL_SCENES
NULL, // Scene Store Request command
NULL, // Scene Recall Request command
NULL, // Scene Response command
#endif
#ifdef ZCL_ALARMS
NULL, // Alarm (Response) commands
#endif
#ifdef SE_UK_EXT
NULL, // Get Event Log command
NULL, // Publish Event Log command
#endif
NULL, // RSSI Location command
NULL // RSSI Location Response command
};
/*********************************************************************
* STATUS STRINGS
*/
#ifdef LCD_SUPPORTED
const char sDeviceName[] = " Sample Switch";
const char sClearLine[] = " ";
const char sSwLight[] = "SW1: ToggleLight";
const char sSwEZMode[] = "SW2: EZ-Mode";
const char sSwHelp[] = "SW5: Help";
const char sCmdSent[] = " COMMAND SENT";
#endif
/*********************************************************************
* @fn zclSampleSw_Init
*
* @brief Initialization function for the zclGeneral layer.
*
* @param none
*
* @return none
*/
void zclSampleSw_Init( byte task_id )
{
zclSampleSw_TaskID = task_id;
#ifdef ZCL_ON_OFF
// Set destination address to indirect
zclSampleSw_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent;
zclSampleSw_DstAddr.endPoint = 0;
zclSampleSw_DstAddr.addr.shortAddr = 0;
//zclSampleSw_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
//zclSampleSw_DstAddr.endPoint = 0x0c;
//zclSampleSw_DstAddr.addr.shortAddr = 0x0c66;
#endif
// This app is part of the Home Automation Profile
zclHA_Init( &zclSampleSw_SimpleDesc );
// Register the ZCL General Cluster Library callback functions
zclGeneral_RegisterCmdCallbacks( SAMPLESW_ENDPOINT, &zclSampleSw_CmdCallbacks );
// Register the application's attribute list
zcl_registerAttrList( SAMPLESW_ENDPOINT, SAMPLESW_MAX_ATTRIBUTES, zclSampleSw_Attrs );
// Register the Application to receive the unprocessed Foundation command/response messages
zcl_registerForMsg( zclSampleSw_TaskID );
#ifdef ZCL_EZMODE
// Register EZ-Mode
zcl_RegisterEZMode( &zclSampleSw_RegisterEZModeData );
// Register with the ZDO to receive Match Descriptor Responses
ZDO_RegisterForZDOMsg(task_id, Match_Desc_rsp);
#endif
// Register for all key events – This app will handle all key events
RegisterForKeys( zclSampleSw_TaskID );
// Register for a test endpoint
afRegister( &sampleSw_TestEp );
ZDO_RegisterForZDOMsg( zclSampleSw_TaskID, End_Device_Bind_rsp );
ZDO_RegisterForZDOMsg( zclSampleSw_TaskID, Match_Desc_rsp );
ZDO_RegisterForZDOMsg( zclSampleSw_TaskID,Bind_rsp);
ZDO_RegisterForZDOMsg( zclSampleSw_TaskID,Unbind_rsp);
#ifdef LCD_SUPPORTED
HalLcdWriteString ( (char *)sDeviceName, HAL_LCD_LINE_3 );
#endif
#if defined (OTA_CLIENT) && (OTA_CLIENT == TRUE)
// Register for callback events from the ZCL OTA
zclOTA_Register(zclSampleSw_TaskID);
#endif
}
/*********************************************************************
* @fn zclSample_event_loop
*
* @brief Event Loop Processor for zclGeneral.
*
* @param none
*
* @return none
*/
uint16 zclSampleSw_event_loop( uint8 task_id, uint16 events )
{
afIncomingMSGPacket_t *MSGpkt;
(void)task_id; // Intentionally unreferenced parameter
if ( events & SYS_EVENT_MSG )
{
while ( (MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( zclSampleSw_TaskID )) )
{
switch ( MSGpkt->hdr.event )
{
#ifdef ZCL_EZMODE
case ZDO_CB_MSG:
zclSampleSw_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt );
break;
#endif
case ZCL_INCOMING_MSG:
// Incoming ZCL Foundation command/response messages
zclSampleSw_ProcessIncomingMsg( (zclIncomingMsg_t *)MSGpkt );
break;
case KEY_CHANGE:
zclSampleSw_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
break;
case ZDO_STATE_CHANGE:
zclSampleSw_NwkState = (devStates_t)(MSGpkt->hdr.status);
// now on the network
if ( (zclSampleSw_NwkState == DEV_ZB_COORD) ||
(zclSampleSw_NwkState == DEV_ROUTER) ||
(zclSampleSw_NwkState == DEV_END_DEVICE) )
{
#ifndef HOLD_AUTO_START
giSwScreenMode = SW_MAINMODE;
zclSampleSw_LcdDisplayUpdate();
#endif
#ifdef ZCL_EZMODE
zcl_EZModeAction( EZMODE_ACTION_NETWORK_STARTED, NULL );
#endif
}
break;
#if defined (OTA_CLIENT) && (OTA_CLIENT == TRUE)
case ZCL_OTA_CALLBACK_IND:
zclSampleSw_ProcessOTAMsgs( (zclOTA_CallbackMsg_t*)MSGpkt );
break;#endif
default:
break;
}
// Release the memory
osal_msg_deallocate( (uint8 *)MSGpkt );
}
// return unprocessed events
return (events ^ SYS_EVENT_MSG);
}
if ( events & SAMPLESW_IDENTIFY_TIMEOUT_EVT )
{
zclSampleSw_IdentifyTime = 10;
zclSampleSw_ProcessIdentifyTimeChange();
return ( events ^ SAMPLESW_IDENTIFY_TIMEOUT_EVT );
}
if ( events & SAMPLESW_MAIN_SCREEN_EVT )
{
giSwScreenMode = SW_MAINMODE;
zclSampleSw_LcdDisplayUpdate();
#ifdef LCD_SUPPORTED
HalLcdWriteString( (char *)sClearLine, HAL_LCD_LINE_2 );
#endif
return ( events ^ SAMPLESW_MAIN_SCREEN_EVT );
}
#ifdef ZCL_EZMODE
if ( events & SAMPLESW_EZMODE_NEXTSTATE_EVT )
{
zcl_EZModeAction ( EZMODE_ACTION_PROCESS, NULL ); // going on to next state
return ( events ^ SAMPLESW_EZMODE_NEXTSTATE_EVT );
}
if ( events & SAMPLESW_EZMODE_TIMEOUT_EVT )
{
zcl_EZModeAction ( EZMODE_ACTION_TIMED_OUT, NULL ); // EZ-Mode timed out
return ( events ^ SAMPLESW_EZMODE_TIMEOUT_EVT );
}
#endif // ZLC_EZMODE
// Discard unknown events
return 0;
}
/*********************************************************************
* @fn zclSampleSw_HandleKeys
*
* @brief Handles all key events for this device.
*
* @param shift – true if in shift/alt.
* @param keys – bit field for key events. Valid entries:
* HAL_KEY_SW_5
* HAL_KEY_SW_4
* HAL_KEY_SW_2
* HAL_KEY_SW_1
*
* @return none
*/
static void zclSampleSw_HandleKeys( byte shift, byte keys )
{
// toggle remote light
if ( keys & HAL_KEY_SW_1 )
{
giSwScreenMode = SW_MAINMODE; // remove help screen if there
// Using this as the "Light Switch"
#ifdef ZCL_ON_OFF
zclGeneral_SendOnOff_CmdToggle( SAMPLESW_ENDPOINT, &zclSampleSw_DstAddr, FALSE, 0 );
#endif
/*zclGeneral_SendLevelControlStepWithOnOff( SAMPLESW_ENDPOINT, &zclSampleSw_DstAddr,
LEVEL_STEP_DOWN, 10,
10, FALSE, zclSampleSwSeqNum++ );*/
//zclGeneral_SendLevelControlMoveToLevel(SAMPLESW_ENDPOINT, &zclSampleSw_DstAddr,0,10,FALSE, zclSampleSwSeqNum++);
#ifdef LCD_SUPPORTED
HalLcdWriteString( (char *)sCmdSent, HAL_LCD_LINE_2 );
// clear message on screen after 3 seconds
osal_start_timerEx( zclSampleSw_TaskID, SAMPLESW_MAIN_SCREEN_EVT, 3000 );
#endif
}
if(keys & HAL_KEY_SW_2)
{
zclGeneral_SendLevelControlStepWithOnOff( SAMPLESW_ENDPOINT, &zclSampleSw_DstAddr,
LEVEL_STEP_UP, 10,
10, FALSE, zclSampleSwSeqNum++ );
//zclGeneral_SendLevelControlMoveToLevel(SAMPLESW_ENDPOINT, &zclSampleSw_DstAddr,0,10,FALSE, zclSampleSwSeqNum++);
}
// invoke EZ-Mode
if ( keys & HAL_KEY_SW_3 )
{
giSwScreenMode = SW_MAINMODE; // remove help screen if there
#ifdef ZCL_EZMODE
{
zclEZMode_InvokeData_t ezModeData;
static uint16 clusterIDs[] = { ZCL_CLUSTER_ID_GEN_ON_OFF }; // only bind on the on/off cluster
// Invoke EZ-Mode
ezModeData.endpoint = SAMPLESW_ENDPOINT; // endpoint on which to invoke EZ-Mode
if ( (zclSampleSw_NwkState == DEV_ZB_COORD) ||
(zclSampleSw_NwkState == DEV_ROUTER) ||
(zclSampleSw_NwkState == DEV_END_DEVICE) )
{
ezModeData.onNetwork = TRUE; // node is already on the network
}
else
{
ezModeData.onNetwork = FALSE; // node is not yet on the network
}
ezModeData.initiator = TRUE; // OnOffSwitch is an initiator
ezModeData.numActiveOutClusters = 1; // active output cluster
ezModeData.pActiveOutClusterIDs = clusterIDs;
ezModeData.numActiveInClusters = 0; // no active input clusters
ezModeData.pActiveInClusterIDs = NULL;
zcl_InvokeEZMode( &ezModeData );
#ifdef LCD_SUPPORTED
HalLcdWriteString( "EZMode", HAL_LCD_LINE_2 );
#endif
}
#else // NOT ZCL_EZMODE
// bind to remote light
zAddrType_t dstAddr;
HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF );
// Initiate an End Device Bind Request, this bind request will
// only use a cluster list that is important to binding.
dstAddr.addrMode = afAddr16Bit;
dstAddr.addr.shortAddr = 0; // Coordinator makes the match
ZDP_EndDeviceBindReq( &dstAddr, NLME_GetShortAddr(),
SAMPLESW_ENDPOINT,
ZCL_HA_PROFILE_ID,
0, NULL, // No incoming clusters to bind
ZCLSAMPLESW_BINDINGLIST, bindingOutClusters,
TRUE );
#endif // ZCL_EZMODE
}
// toggle permit join
if ( keys & HAL_KEY_SW_4 )
{
giSwScreenMode = SW_MAINMODE; // remove help screen if there
if ( ( zclSampleSw_NwkState == DEV_ZB_COORD ) ||
( zclSampleSw_NwkState == DEV_ROUTER ) )
{
// toggle permit join
gPermitDuration = gPermitDuration ? 0 : 0xff;
NLME_PermitJoiningRequest( gPermitDuration );
}
}
if ( shift && ( keys & HAL_KEY_SW_5 ) )
{
zclSampleSw_BasicResetCB();
}
else if ( keys & HAL_KEY_SW_5 )
{
giSwScreenMode = giSwScreenMode ? SW_MAINMODE : SW_HELPMODE;
#ifdef LCD_SUPPORTED
HalLcdWriteString( (char *)sClearLine, HAL_LCD_LINE_2 );
#endif
}
// update the display
zclSampleSw_LcdDisplayUpdate();
}
/*********************************************************************
* @fn zclSampleSw_LcdDisplayUpdate
*
* @brief Called to update the LCD display.
*
* @param none
*
* @return none
*/
void zclSampleSw_LcdDisplayUpdate(void)
{
if ( giSwScreenMode == SW_HELPMODE )
{
zclSampleSw_LcdDisplayHelpMode();
}
else
{
zclSampleSw_LcdDisplayMainMode();
}
}
/*********************************************************************
* @fn zclSampleSw_LcdDisplayMainMode
*
* @brief Called to display the main screen on the LCD.
*
* @param none
*
* @return none
*/
void zclSampleSw_LcdDisplayMainMode(void)
{
if ( zclSampleSw_NwkState == DEV_ZB_COORD )
{
zclHA_LcdStatusLine1(0);
}
else if ( zclSampleSw_NwkState == DEV_ROUTER )
{
zclHA_LcdStatusLine1(1);
}
else if ( zclSampleSw_NwkState == DEV_END_DEVICE )
{
zclHA_LcdStatusLine1(2);
}
#ifdef LCD_SUPPORTED
if ( ( zclSampleSw_NwkState == DEV_ZB_COORD ) ||
( zclSampleSw_NwkState == DEV_ROUTER ) )
{
// display help key with permit join status
if ( gPermitDuration )
{
HalLcdWriteString("SW5: Help *", HAL_LCD_LINE_3);
}
else
{
HalLcdWriteString("SW5: Help ", HAL_LCD_LINE_3);
}
}
else
{
// display help key
HalLcdWriteString((char *)sSwHelp, HAL_LCD_LINE_3);
}
#endif
}
/*********************************************************************
* @fn zclSampleSw_LcdDisplayHelpMode
*
* @brief Called to display the SW options on the LCD.
*
* @param none
*
* @return none
*/
void zclSampleSw_LcdDisplayHelpMode(void)
{
#ifdef LCD_SUPPORTED
HalLcdWriteString( (char *)sSwLight, HAL_LCD_LINE_1 );
HalLcdWriteString( (char *)sSwEZMode, HAL_LCD_LINE_2 );
HalLcdWriteString( (char *)sSwHelp, HAL_LCD_LINE_3 );
#endif
}
/*********************************************************************
* @fn zclSampleSw_ProcessIdentifyTimeChange
*
* @brief Called to process any change to the IdentifyTime attribute.
*
* @param none
*
* @return none
*/
static void zclSampleSw_ProcessIdentifyTimeChange( void )
{
if ( zclSampleSw_IdentifyTime > 0 )
{
osal_start_timerEx( zclSampleSw_TaskID, SAMPLESW_IDENTIFY_TIMEOUT_EVT, 1000 );
HalLedBlink ( HAL_LED_4, 0xFF, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME );
}
else
{
if ( zclSampleSw_OnOff )
HalLedSet ( HAL_LED_4, HAL_LED_MODE_ON );
else
HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF );
osal_stop_timerEx( zclSampleSw_TaskID, SAMPLESW_IDENTIFY_TIMEOUT_EVT );
}
}
/*********************************************************************
* @fn zclSampleSw_BasicResetCB
*
* @brief Callback from the ZCL General Cluster Library
* to set all the Basic Cluster attributes to default values.
*
* @param none
*
* @return none
*/
static void zclSampleSw_BasicResetCB( void )
{
// Put device back to factory default settings
zgWriteStartupOptions( ZG_STARTUP_SET, 3 ); // bit set both default configuration and default network
// restart device
MT_SysCommandProcessing( aProcessCmd );
}
/*********************************************************************
* @fn zclSampleSw_IdentifyCB
*
* @brief Callback from the ZCL General Cluster Library when
* it received an Identity Command for this application.
*
* @param srcAddr – source address and endpoint of the response message
* @param identifyTime – the number of seconds to identify yourself
*
* @return none
*/
static void zclSampleSw_IdentifyCB( zclIdentify_t *pCmd )
{
zclSampleSw_IdentifyTime = pCmd->identifyTime;
zclSampleSw_ProcessIdentifyTimeChange();
}
/*********************************************************************
* @fn zclSampleSw_IdentifyQueryRspCB
*
* @brief Callback from the ZCL General Cluster Library when
* it received an Identity Query Response Command for this application.
*
* @param srcAddr – source address
* @param timeout – number of seconds to identify yourself (valid for query response)
*
* @return none
*/
static void zclSampleSw_IdentifyQueryRspCB( zclIdentifyQueryRsp_t *pRsp )
{
(void)pRsp;
#ifdef ZCL_EZMODE
{
zclEZMode_ActionData_t data;
data.pIdentifyQueryRsp = pRsp;
zcl_EZModeAction ( EZMODE_ACTION_IDENTIFY_QUERY_RSP, &data );
}
#endif
}
/******************************************************************************
*
* Functions for processing ZCL Foundation incoming Command/Response messages
*
*****************************************************************************/
/*********************************************************************
* @fn zclSampleSw_ProcessIncomingMsg
*
* @brief Process ZCL Foundation incoming message
*
* @param pInMsg – pointer to the received message
*
* @return none
*/
static void zclSampleSw_ProcessIncomingMsg( zclIncomingMsg_t *pInMsg )
{
switch ( pInMsg->zclHdr.commandID )
{
#ifdef ZCL_READ
case ZCL_CMD_READ_RSP:
zclSampleSw_ProcessInReadRspCmd( pInMsg );
break;
#endif
#ifdef ZCL_WRITE
case ZCL_CMD_WRITE_RSP:
zclSampleSw_ProcessInWriteRspCmd( pInMsg );
break;
#endif
#ifdef ZCL_REPORT
// See ZCL Test Applicaiton (zcl_testapp.c) for sample code on Attribute Reporting
case ZCL_CMD_CONFIG_REPORT:
//zclSampleSw_ProcessInConfigReportCmd( pInMsg );
break;
case ZCL_CMD_CONFIG_REPORT_RSP:
//zclSampleSw_ProcessInConfigReportRspCmd( pInMsg );
break;
case ZCL_CMD_READ_REPORT_CFG:
//zclSampleSw_ProcessInReadReportCfgCmd( pInMsg );
break;
case ZCL_CMD_READ_REPORT_CFG_RSP:
//zclSampleSw_ProcessInReadReportCfgRspCmd( pInMsg );
break;
case ZCL_CMD_REPORT:
//zclSampleSw_ProcessInReportCmd( pInMsg );
break;
#endif
case ZCL_CMD_DEFAULT_RSP:
zclSampleSw_ProcessInDefaultRspCmd( pInMsg );
break;
#ifdef ZCL_DISCOVER
case ZCL_CMD_DISCOVER_CMDS_RECEIVED_RSP:
zclSampleSw_ProcessInDiscCmdsRspCmd( pInMsg );
break;
case ZCL_CMD_DISCOVER_CMDS_GEN_RSP:
zclSampleSw_ProcessInDiscCmdsRspCmd( pInMsg );
break;
case ZCL_CMD_DISCOVER_ATTRS_RSP:
zclSampleSw_ProcessInDiscAttrsRspCmd( pInMsg );
break;
case ZCL_CMD_DISCOVER_ATTRS_EXT_RSP:
zclSampleSw_ProcessInDiscAttrsExtRspCmd( pInMsg );
break;
#endif
default:
break;
}
if ( pInMsg->attrCmd )
osal_mem_free( pInMsg->attrCmd );
}
#ifdef ZCL_READ
/*********************************************************************
* @fn zclSampleSw_ProcessInReadRspCmd
*
* @brief Process the "Profile" Read Response Command
*
* @param pInMsg – incoming message to process
*
* @return none
*/
static uint8 zclSampleSw_ProcessInReadRspCmd( zclIncomingMsg_t *pInMsg )
{
zclReadRspCmd_t *readRspCmd;
uint8 i;
readRspCmd = (zclReadRspCmd_t *)pInMsg->attrCmd;
for (i = 0; i < readRspCmd->numAttr; i++)
{
// Notify the originator of the results of the original read attributes
// attempt and, for each successfull request, the value of the requested
// attribute
}
return TRUE;
}
#endif // ZCL_READ
#ifdef ZCL_WRITE
/*********************************************************************
* @fn zclSampleSw_ProcessInWriteRspCmd
*
* @brief Process the "Profile" Write Response Command
*
* @param pInMsg – incoming message to process
*
* @return none
*/
static uint8 zclSampleSw_ProcessInWriteRspCmd( zclIncomingMsg_t *pInMsg )
{
zclWriteRspCmd_t *writeRspCmd;
uint8 i;
writeRspCmd = (zclWriteRspCmd_t *)pInMsg->attrCmd;
for (i = 0; i < writeRspCmd->numAttr; i++)
{
// Notify the device of the results of the its original write attributes
// command.
}
return TRUE;
}
#endif // ZCL_WRITE
/*********************************************************************
* @fn zclSampleSw_ProcessInDefaultRspCmd
*
* @brief Process the "Profile" Default Response Command
*
* @param pInMsg – incoming message to process
*
* @return none
*/
static uint8 zclSampleSw_ProcessInDefaultRspCmd( zclIncomingMsg_t *pInMsg )
{
// zclDefaultRspCmd_t *defaultRspCmd = (zclDefaultRspCmd_t *)pInMsg->attrCmd;
// Device is notified of the Default Response command.
(void)pInMsg;
return TRUE;
}
#ifdef ZCL_DISCOVER
/*********************************************************************
* @fn zclSampleSw_ProcessInDiscCmdsRspCmd
*
* @brief Process the Discover Commands Response Command
*
* @param pInMsg – incoming message to process
*
* @return none
*/
static uint8 zclSampleSw_ProcessInDiscCmdsRspCmd( zclIncomingMsg_t *pInMsg )
{
zclDiscoverCmdsCmdRsp_t *discoverRspCmd;
uint8 i;
discoverRspCmd = (zclDiscoverCmdsCmdRsp_t *)pInMsg->attrCmd;
for ( i = 0; i < discoverRspCmd->numCmd; i++ )
{
// Device is notified of the result of its attribute discovery command.
}
return TRUE;
}
/*********************************************************************
* @fn zclSampleSw_ProcessInDiscAttrsRspCmd
*
* @brief Process the "Profile" Discover Attributes Response Command
*
* @param pInMsg – incoming message to process
*
* @return none
*/
static uint8 zclSampleSw_ProcessInDiscAttrsRspCmd( zclIncomingMsg_t *pInMsg )
{
zclDiscoverAttrsRspCmd_t *discoverRspCmd;
uint8 i;
discoverRspCmd = (zclDiscoverAttrsRspCmd_t *)pInMsg->attrCmd;
for ( i = 0; i < discoverRspCmd->numAttr; i++ )
{
// Device is notified of the result of its attribute discovery command.
}
return TRUE;
}
/*********************************************************************
* @fn zclSampleSw_ProcessInDiscAttrsExtRspCmd
*
* @brief Process the "Profile" Discover Attributes Extended Response Command
*
* @param pInMsg – incoming message to process
*
* @return none
*/
static uint8 zclSampleSw_ProcessInDiscAttrsExtRspCmd( zclIncomingMsg_t *pInMsg )
{
zclDiscoverAttrsExtRsp_t *discoverRspCmd;
uint8 i;
discoverRspCmd = (zclDiscoverAttrsExtRsp_t *)pInMsg->attrCmd;
for ( i = 0; i < discoverRspCmd->numAttr; i++ )
{
// Device is notified of the result of its attribute discovery command.
}
return TRUE;
}
#endif // ZCL_DISCOVER
#if ZCL_EZMODE
/*********************************************************************
* @fn zclSampleSw_ProcessZDOMsgs
*
* @brief Called when this node receives a ZDO/ZDP response.
*
* @param none
*
* @return status
*/
static void zclSampleSw_ProcessZDOMsgs( zdoIncomingMsg_t *pMsg )
{
// Let EZ-Mode know of the Match Descriptor Reponse (same as ActiveEP Response)
if ( pMsg->clusterID == Match_Desc_rsp )
{
zclEZMode_ActionData_t data;
ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( pMsg );
data.pMatchDescRsp = pRsp;
zcl_EZModeAction( EZMODE_ACTION_MATCH_DESC_RSP, &data );
osal_mem_free(pRsp);
}
}
/*********************************************************************
* @fn zclSampleSw_EZModeCB
*
* @brief The Application is informed of events. This can be used to show on the UI what is
* going on during EZ-Mode steering/finding/binding.
*
* @param state – an
*
* @return none
*/
static void zclSampleSw_EZModeCB( zlcEZMode_State_t state, zclEZMode_CBData_t *pData )
{
#ifdef LCD_SUPPORTED
char szLine[20];
char *pStr;
uint8 err;
#endif
// time to go into identify mode
if ( state == EZMODE_STATE_IDENTIFYING )
{
zclSampleSw_IdentifyTime = (EZMODE_TIME / 1000); // convert to seconds
zclSampleSw_ProcessIdentifyTimeChange();
}
// autoclosing, show what happened (success, cancelled, etc…)
if( state == EZMODE_STATE_AUTOCLOSE )
{
#ifdef LCD_SUPPORTED
pStr = NULL;
err = pData->sAutoClose.err;
if ( err == EZMODE_ERR_SUCCESS )
{
pStr = "EZMode: Success";
}
else if ( err == EZMODE_ERR_NOMATCH )
{
pStr = "EZMode: NoMatch"; // not a match made in heaven
}
if ( pStr )
{
if ( giSwScreenMode == SW_MAINMODE )
HalLcdWriteString ( pStr, HAL_LCD_LINE_2 );
}
#endif
}
// finished, either show DstAddr/EP, or nothing (depending on success or not)
if( state == EZMODE_STATE_FINISH )
{
// turn off identify mode
zclSampleSw_IdentifyTime = 0;
zclSampleSw_ProcessIdentifyTimeChange();
#ifdef LCD_SUPPORTED
// if successful, inform user which nwkaddr/ep we bound to
pStr = NULL;
err = pData->sFinish.err;
if( err == EZMODE_ERR_SUCCESS )
{
// "EZDst:1234 EP:34"
osal_memcpy(szLine, "EZDst:", 6);
zclHA_uint16toa( pData->sFinish.nwkaddr, &szLine[6]);
osal_memcpy(&szLine[10], " EP:", 4);
_ltoa( pData->sFinish.ep, (void *)(&szLine[14]), 16 ); // _ltoa NULL terminates
pStr = szLine;
}
else if ( err == EZMODE_ERR_BAD_PARAMETER )
{
pStr = "EZMode: BadParm";
}
else if ( err == EZMODE_ERR_CANCELLED )
{
pStr = "EZMode: Cancel";
}
else
{
pStr = "EZMode: TimeOut";
}
if ( pStr )
{
if ( giSwScreenMode == SW_MAINMODE )
HalLcdWriteString ( pStr, HAL_LCD_LINE_2 );
}
#endif // LCD_SUPPORTED
// show main UI screen 3 seconds after binding
osal_start_timerEx( zclSampleSw_TaskID, SAMPLESW_MAIN_SCREEN_EVT, 3000 );
}
}
#endif // ZCL_EZMODE
#if defined (OTA_CLIENT) && (OTA_CLIENT == TRUE)
/*********************************************************************
* @fn zclSampleSw_ProcessOTAMsgs
*
* @brief Called to process callbacks from the ZCL OTA.
*
* @param none
*
* @return none
*/
static void zclSampleSw_ProcessOTAMsgs( zclOTA_CallbackMsg_t* pMsg )
{
uint8 RxOnIdle;
switch(pMsg->ota_event)
{
case ZCL_OTA_START_CALLBACK:
if (pMsg->hdr.status == ZSuccess)
{
// Speed up the poll rate
RxOnIdle = TRUE;
ZMacSetReq( ZMacRxOnIdle, &RxOnIdle );
NLME_SetPollRate( 2000 );
}
break;
case ZCL_OTA_DL_COMPLETE_CALLBACK:
if (pMsg->hdr.status == ZSuccess)
{
// Reset the CRC Shadow and reboot. The bootloader will see the
// CRC shadow has been cleared and switch to the new image
HalOTAInvRC();
SystemReset();
}
else
{
// slow the poll rate back down.
RxOnIdle = FALSE;
ZMacSetReq( ZMacRxOnIdle, &RxOnIdle );
NLME_SetPollRate(DEVICE_POLL_RATE);
}
break;
default:
break;
}
}
#endif // defined (OTA_CLIENT) && (OTA_CLIENT == TRUE)
/****************************************************************************
****************************************************************************/
VV:
你的调光器在某个end point上面有没有level Controller的output cluster
jinbin chen:
回复 VV:
问题解决了,谢谢
网关代码只绑定了CLUSTER_ID_ONOFF,没有绑定level cluster id
dst_addr.ieee_addr = ds_device_table[selected_device_index].ieee_addr; dst_addr.endpoint = ds_device_table[selected_device_index].ep_list[ds_device_table[selected_device_index].selected_endpoint_index].endpoint_id;
comm_device_binding_entry_request(&source_addr, &dst_addr, CLUSTER_ID_ONOFF, binding_mode);
ds_device_table[binding_source_device_index].selected_as_bind_destination = false;
ui_redraw_device_list();
VV:
回复 jinbin chen:
好的,加油!
能否私信告诉我下,你们公司,谢谢!
huibin zhao:
回复 jinbin chen:
大哥,我搞Linux Gateway 移植出现点问题,可以帮帮兄弟吧,QQ:1060870968,谢谢了。
lihua yang:
回复 VV:
Ti工程师:
您好!我在编译Z-Stack_Linux_Gateway-1.0.1时遇到一些问题如下,肯请赐教,谢谢!
问题描述:Z-Stack_Linux_Gateway-1.0.1移植到MT7620 上,其平台为mipsel-linux ,所以其对应的编译器需要用到7620的编译器/opt/buildroot-gcc342/bin/mipsel-linux-uclibc-gcc,于是我修改build_sample_app里面的CC=mipsel-linux-uclibc-gcc,编译后会出现execinfo.h No such file or Directory的错误,分析后发现Z-Stack_Linux_Gateway-1.0.1\Source\protobuf-c-arm\lib 这个库的配置会有影响,所以我想请问下 要如何编译获得对应的mips平台上的库文件?需要用mipsel-linux-uclibc-gcc来编译哪些文件?
jinbin chen:
回复 lihua yang:
里面的protobuf是arm平台的,你上谷歌搜索有没有protobuf-c的源码,如果有就在mips编译。但是Z-Stack_Linux_Gateway-1.0.1中底层的网关服务是基于debian编译出来的,也没有源码。即使app编译通过,估计也用不了,MT7620能否装debian试试。
Di Li2:
回复 jinbin chen:
想问下您Z-Stack_Linux_Gateway如何绑定cc2530的彩灯呢?我想要用zigbee use dongle连接zigbee彩灯,终端是树莓派,要如何实现呢?希望您能帮忙。谢谢了
jinbin chen:
回复 Di Li2:
把zigbee设备加进网络,使用socket去操作,参考文档Z-Stack Linux Gateway – API document v1.1 里面有命令
Di Li2:
回复 jinbin chen:
我也出现了编译问题,树莓派是armv7,Zigbee linux gateway网关文件是x86的没法运行啊,很伤心,不知道怎么解决