hey any ideas about transmission of control signals from coordinator to sensor node
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
hey any ideas about transmission of control signals from coordinator to sensor node
can this be used to send control signals like on/off a light from coordinator to a sensor node . and what should i use to send sensor data from sensor node to coordinator sir
If you install Z-Stack Home, there is SampleLight/SampleSwitch to show you how to send toggle command and SampleTmperature to show you how to send temperature data.
i am using samplesw pgm and i have to use 2 sensor nodes and
1) i have to receive data from 1 node and check if it s below the set threshold value
2) when the if the data s above the threshold value i have to send a control signal from coordinator to another sensor node .
can anyone give me any suggessions on how to achieve this scenario
yes sir in that sample light/switch pgm i couldnt find where is the command for transmitting the commands for switching on the light and in the end device where the command is recceived and processed to switch on the light
1. You can refer to zclSampleSw_HandleKeys() in SampleSwitch example to see it uses zclGeneral_SendOnOff_CmdToggle() to send toggle command.
2. You can build SampleSwitch as ZC, SampleTemperature as ZED, and SampleLight as ZR. So, you can make ZED reports temperature to ZC and check if the temperature is greater/less than threshold. Then, send on/off command form ZC accordingly.
Sir , actually i am a beginner what r u telling about ZC , ZD and ZED .... can u send me some documents which i can refer or give a small explanation
You can try to refer to the books guide at http://www.zigbee.org/LearnMore/BooksGuides.aspx.
2. You can build SampleSwitch as ZC, SampleTemperature as ZED, and SampleLight as ZR. So, you can make ZED reports temperature to ZC and check if the temperature is greater/less than threshold. Then, send on/off command form ZC accordingly.
how to accomplish the above idea
You can refer to Z-Stack Home Sample Application User's Guide.pdf in Z-Stack Home 1.2.1 Documents folder.
in sample switch i was able 2 identify the function used for sending commands in the switch handling function .. s thr any way to get it out of that switch handling function and use it like
static void SampleSw_OnOff ();
{
INT8 i=3;
if(i=3)
{
#ifdef ZCL_ON_OFF
zclGeneral_SendOnOff_CmdOn( SAMPLESW_ENDPOINT, &zclSampleSw_DstAddr, false, 0 );
#endif
}
}
Yes, you can use it else where. However, you should not use a for loop to send zclGeneral_SendOnOff_CmdOn(). There should be some non-blocking delay between zclGeneral_SendOnOff_CmdOn.
yes sir i got it but i couldnt use the function i declared above in the real program . any suggestions ???
Do you mean you can't use zclGeneral_SendOnOff_CmdOn()? It is defined in zcl_general.h and you should include it in your C files.
i can use it sir .. the pblm is in sample switch program of home automation the function zclGeneral_SendOnOff_CmdOn() is written in the function zclSampleSw_HandleKeys and every time i click the button in coordinator node led of sensor node is blinking ..
now i have to use the function zclGeneral_SendOnOff_CmdOn() for checking a integer i r sumthing and without using that button while i check the condition and if the condition is true the light in sensor node should glow
i can use it sir .. the pblm is in sample switch program of home automation the function zclGeneral_SendOnOff_CmdOn() is written in the function zclSampleSw_HandleKeys and every time i click the button in coordinator node led of sensor node is blinking ..
now i have to use the function zclGeneral_SendOnOff_CmdOn() for checking a integer i r sumthing and without using that button while i check the condition and if the condition is true the light in sensor node should glow
yes sir i can call it but don't know where
1) i tried in zcl_samplesw.c in the function static void zclSampleSw_HandleKeys( byte shift, byte keys ) itself but it is not wrking i removed the key press condition and added condition checking part
2)i tried in ZMain.c as a function like
static void zmain_control( void )
{
int i=3;
if(i=3)
{
#ifdef ZCL_ON_OFF
zclGeneral_SendOnOff_CmdOn( SAMPLESW_ENDPOINT, &zclSampleSw_DstAddr, false, 0 );
#endif
}
}
but still not working .
help me out pl
If you put zclGeneral_SendOnOff_CmdOn in Key event handler, it should only work when you press the key to trigger key event. I would suggest you to create a periodic event to check your own condition and if it satisfies the condition, call zclGeneral_SendOnOff_CmdOn.
how 2 create such periodic event sir .. i tried to create a function in zcl_samplesw.c file to check the condition and to call the function zclGeneral_SendOnOff_CmdOn .. but it does not seems to be executing as per i imagined it to be ..
You can start the PERIODIC_EVT when there is ZDO_STATE_CHANGE by calling the folling function:
osal_start_timerEx( zclXXX_TaskID, PERIODIC_EVT , 5000 );
Then, create event processor in event loop as the followings:
if ( events & PERIODIC_EVT )
{
if(...) // check condition to send toggle command.
{
//Send toggle command here.
}
osal_start_timerEx( zclXXX_TaskID, PERIODIC_EVT , 5000 );
return ( events ^ PERIODIC_EVT );
}
sir already there is a function for the "osal_start_timerEx" ......
uint8 osal_start_timerEx( uint8 taskID, uint16 event_id, uint16 timeout_value )
{
halIntState_t intState;
osalTimerRec_t *newTimer;
HAL_ENTER_CRITICAL_SECTION( intState ); // Hold off interrupts.
// Add timer
newTimer = osalAddTimer( taskID, event_id, timeout_value );
HAL_EXIT_CRITICAL_SECTION( intState ); // Re-enable interrupts.
return ( (newTimer != NULL) ? SUCCESS : NO_TIMER_AVAIL );
}
osal_start_timerEx is a Z-Stack API that will create a event after some delay. Using my pseudo-code, you can create a periodic event to check your condition. When the condition is true, you can send toggle command.
for each periodic evnt there s a define function written like
#define HAL_KEY_EVENT 0x0001
what does that constant corresponds and how can i write PERIODIC EVENT like that
If you use SampleSwitch as example, you can add the following define in zcl_samplesw.h
#define PERIODIC_EVT 0x0020
Then add the following code in zclSampleSw_event_loop().
if ( events & PERIODIC_EVT )
{
if(...) // check condition to send toggle command.
{
//Send toggle command here.
}
osal_start_timerEx( zclXXX_TaskID, PERIODIC_EVT , 5000 );
return ( events ^ PERIODIC_EVT );
}
this i s how i modified the function but yet the led of sensor node it not glowing via signal frm coordinator board sir ..
but the pgm is executing without errors..
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 )
{
case ZCL_INCOMING_MSG:
// Incoming ZCL Foundation command/response messages
zclSampleSw_ProcessIncomingMsg( (zclIncomingMsg_t *)MSGpkt );
break;
case ZDO_CB_MSG:
zclSampleSw_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt );
break;
case KEY_CHANGE:
zclSampleSw_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
break;
default:
break;
}
// Release the memory
osal_msg_deallocate( (uint8 *)MSGpkt );
}
// return unprocessed events
return (events ^ SYS_EVENT_MSG);
}
if ( events & PERIODIC_EVT )
{
int i=3;
if(i == 3) // check condition to send toggle command.
{
zclGeneral_SendOnOff_CmdOn( SAMPLESW_ENDPOINT, &zclSampleSw_DstAddr, false, 0 ); //Send toggle command here.
}
osal_start_timerEx( zclSampleSw_TaskID, PERIODIC_EVT , 5000 );
return ( events ^ PERIODIC_EVT);
}
/*if ( events & SAMPLESW_IDENTIFY_TIMEOUT_EVT )
{
zclSampleSw_IdentifyTime = 10;
zclSampleSw_ProcessIdentifyTimeChange();
return ( events ^ SAMPLESW_IDENTIFY_TIMEOUT_EVT );
}*/
// Discard unknown events
return 0;
}
Do you call osal_start_timerEx( zclSampleSw_TaskID, PERIODIC_EVT , 5000 ) to start event in ZDO_STATE_CHANGE like the followings?
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) )
{
osal_start_timerEx( zclSampleSw_TaskID, PERIODIC_EVT , 5000 );
....
}
no sir i didnt change in any other files and all .. i just changed the zcl_sampleSw.c file only sir .. where should i apply the above changes you told .
You should add the following red line in zclSampleSw_event_loop().
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) )
{
osal_start_timerEx( zclSampleSw_TaskID, PERIODIC_EVT , 5000 );
....
}
i did it sir as u said ... i pasted my pgm in my previous comment sir .. yet it s not wrking
when i give this lines
You should add the following red line in zclSampleSw_event_loop().
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) )
{
osal_start_timerEx( zclSampleSw_TaskID, PERIODIC_EVT , 5000 );
....
}
it says that zclSampleSw_NwkState is not defined !!!
So, you don't revise your application based on SampleSwitch right? You should find a variable like zclXXX_NwkState and replace zclSampleSw_NwkState with it.
din't get u there sir .,, what do u meant by not revising application based on sample switch ??
and is zcl_sampleSw_NwkState a variable or a function ???
zcl_sampleSw_NwkState is a variable. Would you attach your C file to allow me to have a look?
bt i couldnt find it used anywhere in my pgm sir ..
/**************************************************************************************************
Filename: zcl_samplesw.c
Revised: $Date: 2009-03-18 15:56:27 -0700 (Wed, 18 Mar 2009) $
Revision: $Revision: 19453 $
Description: Zigbee Cluster Library - sample device application.
Copyright 2006-2009 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 �AS 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.
*********************************************************************/
/*********************************************************************
* INCLUDES
*/
#include "ZComDef.h"
#include "OSAL.h"
#include "AF.h"
#include "ZDApp.h"
#include "ZDObject.h"
#include "ZDProfile.h"
#include "zcl.h"
#include "zcl_general.h"
#include "zcl_ha.h"
#include "zcl_samplesw.h"
#include "onboard.h"
/* HAL */
#include "hal_lcd.h"
#include "hal_led.h"
#include "hal_key.h"
/*********************************************************************
* MACROS
*/
/*********************************************************************
* CONSTANTS
*/
/*********************************************************************
* TYPEDEFS
*/
/*********************************************************************
* GLOBAL VARIABLES
*/
byte zclSampleSw_TaskID;
/*********************************************************************
* GLOBAL FUNCTIONS
*/
/*********************************************************************
* LOCAL VARIABLES
*/
static afAddrType_t zclSampleSw_DstAddr;
#define ZCLSAMPLESW_BINDINGLIST 1
static cId_t bindingOutClusters[ZCLSAMPLESW_BINDINGLIST] =
{
ZCL_CLUSTER_ID_GEN_ON_OFF
};
// Test Endpoint to allow SYS_APP_MSGs
static endPointDesc_t sampleSw_TestEp =
{
20, // Test endpoint
&zclSampleSw_TaskID,
(SimpleDescriptionFormat_t *)NULL, // No Simple description for this test endpoint
(afNetworkLatencyReq_t)0 // No Network Latency req
};
/*********************************************************************
* LOCAL FUNCTIONS
*/
static void zclSampleSw_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg );
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 );
// 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_ProcessInDiscRspCmd( zclIncomingMsg_t *pInMsg );
#endif
/*********************************************************************
* ZCL General Profile Callback table
*/
static zclGeneral_AppCallbacks_t zclSampleSw_CmdCallbacks =
{
zclSampleSw_BasicResetCB, // Basic Cluster Reset command
zclSampleSw_IdentifyCB, // Identify command
zclSampleSw_IdentifyQueryRspCB, // Identify Query Response command
NULL, // On / Off cluster command - not needed.
NULL, // Level Control Move to Level command
NULL, // Level Control Move command
NULL, // Level Control Step command
NULL, // Group Response commands
NULL, // Scene Store Request command
NULL, // Scene Recall Request command
NULL, // Scene Response commands
NULL, // Alarm (Response) commands
NULL, // RSSI Location commands
NULL, // RSSI Location Response commands
};
/*********************************************************************
* @fn zclSampleSw_Init
*
* @brief Initialization function for the zclGeneral layer.
*
* @param none
*
* @return none
*/
void zclSampleSw_Init( byte task_id )
{
zclSampleSw_TaskID = task_id;
// Set destination address to indirect
zclSampleSw_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent;
zclSampleSw_DstAddr.endPoint = 0;
zclSampleSw_DstAddr.addr.shortAddr = 0;
// 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 );
// 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 );
}
/*********************************************************************
* @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 )
{
case ZCL_INCOMING_MSG:
// Incoming ZCL Foundation command/response messages
zclSampleSw_ProcessIncomingMsg( (zclIncomingMsg_t *)MSGpkt );
break;
case ZDO_CB_MSG:
zclSampleSw_ProcessZDOMsgs( (zdoIncomingMsg_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) )
{
osal_start_timerEx( zclSampleSw_TaskID, PERIODIC_EVT , 5000 );
}
default:
break;
}
// Release the memory
osal_msg_deallocate( (uint8 *)MSGpkt );
}
// return unprocessed events
return (events ^ SYS_EVENT_MSG);
}
if ( events & PERIODIC_EVT )
{
int i=3;
if(i == 3) // check condition to send toggle command.
{
zclGeneral_SendOnOff_CmdOn( SAMPLESW_ENDPOINT, &zclSampleSw_DstAddr, false, 0 ); //Send toggle command here.
}
osal_start_timerEx( zclSampleSw_TaskID, PERIODIC_EVT , 1000 );
return ( events ^ PERIODIC_EVT);
}
/*if ( events & SAMPLESW_IDENTIFY_TIMEOUT_EVT )
{
zclSampleSw_IdentifyTime = 10;
zclSampleSw_ProcessIdentifyTimeChange();
return ( events ^ SAMPLESW_IDENTIFY_TIMEOUT_EVT );
}*/
// Discard unknown events
return 0;
}
/*********************************************************************
* @fn zclSampleSw_ProcessZDOMsgs()
*
* @brief Process response messages
*
* @param none
*
* @return none
*/
void zclSampleSw_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg )
{
switch ( inMsg->clusterID )
{
case End_Device_Bind_rsp:
if ( ZDO_ParseBindRsp( inMsg ) == ZSuccess )
{
// Light LED
HalLedSet( HAL_LED_4, HAL_LED_MODE_ON );
}
#if defined(BLINK_LEDS)
else
{
// Flash LED to show failure
HalLedSet ( HAL_LED_4, HAL_LED_MODE_FLASH );
}
#endif
break;
case Match_Desc_rsp:
{
ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( inMsg );
if ( pRsp )
{
if ( pRsp->status == ZSuccess && pRsp->cnt )
{
zclSampleSw_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
zclSampleSw_DstAddr.addr.shortAddr = pRsp->nwkAddr;
// Take the first endpoint, Can be changed to search through endpoints
zclSampleSw_DstAddr.endPoint = pRsp->epList[0];
// Light LED
HalLedSet( HAL_LED_4, HAL_LED_MODE_ON );
}
osal_mem_free( pRsp );
}
}
break;
}
}
/*********************************************************************
* @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_4
* HAL_KEY_SW_3
* HAL_KEY_SW_2
* HAL_KEY_SW_1
*
* @return none
*/
static void zclSampleSw_HandleKeys( byte shift, byte keys )
{
zAddrType_t dstAddr;
(void)shift; // Intentionally unreferenced parameter
//if ( keys & HAL_KEY_SW_1 )
/*if ( keys & HAL_KEY_SW_6 )
{
// Using this as the "Light Switch"
#ifdef ZCL_ON_OFF
zclGeneral_SendOnOff_CmdToggle( SAMPLESW_ENDPOINT, &zclSampleSw_DstAddr, false, 0 );
#endif
}*/
//if ( keys & HAL_KEY_SW_2 )
if ( keys & HAL_KEY_SW_7 )
{
HalLedSet ( HAL_LED_4, HAL_LED_MODE_ON );
// 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 );
}
if ( keys & HAL_KEY_SW_3 )
{
}
//if ( keys & HAL_KEY_SW_4 )
if ( keys & HAL_KEY_SW_8 )
{
HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF );
// Initiate a Match Description Request (Service Discovery)
dstAddr.addrMode = AddrBroadcast;
dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR;
ZDP_MatchDescReq( &dstAddr, NWK_BROADCAST_SHORTADDR,
ZCL_HA_PROFILE_ID,
ZCLSAMPLESW_BINDINGLIST, bindingOutClusters,
0, NULL, // No incoming clusters to bind
FALSE );
}
}
/*********************************************************************
* @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 )
{
}
/*********************************************************************
* @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 )
{
// Query Response (with timeout value)
(void)pRsp;
}
/******************************************************************************
*
* 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_RSP:
zclSampleSw_ProcessInDiscRspCmd( 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_ProcessInDiscRspCmd
*
* @brief Process the "Profile" Discover Response Command
*
* @param pInMsg - incoming message to process
*
* @return none
*/
static uint8 zclSampleSw_ProcessInDiscRspCmd( zclIncomingMsg_t *pInMsg )
{
zclDiscoverRspCmd_t *discoverRspCmd;
uint8 i;
discoverRspCmd = (zclDiscoverRspCmd_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
/****************************************************************************
****************************************************************************/
/**************************************************************************************************
Filename: OSAL_SampleSw.c
Revised: $Date: 2008-02-07 12:10:00 -0800 (Thu, 07 Feb 2008) $
Revision: $Revision: 16360 $
Description: This file contains all the settings and other functions
that the user should set and change.
Copyright 2006-2007 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 �AS 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.
**************************************************************************************************/
/*********************************************************************
* INCLUDES
*/
#include "ZComDef.h"
#include "hal_drivers.h"
#include "OSAL.h"
#include "OSAL_Tasks.h"
#if defined ( MT_TASK )
#include "MT.h"
#include "MT_TASK.h"
#endif
#include "nwk.h"
#include "APS.h"
#include "ZDApp.h"
#if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )
#include "ZDNwkMgr.h"
#endif
#if defined ( ZIGBEE_FRAGMENTATION )
#include "aps_frag.h"
#endif
#include "zcl_samplesw.h"
/*********************************************************************
* GLOBAL VARIABLES
*/
// The order in this table must be identical to the task initialization calls below in osalInitTask.
const pTaskEventHandlerFn tasksArr[] = {
macEventLoop,
nwk_event_loop,
Hal_ProcessEvent,
#if defined( MT_TASK )
MT_ProcessEvent,
#endif
APS_event_loop,
#if defined ( ZIGBEE_FRAGMENTATION )
APSF_ProcessEvent,
#endif
ZDApp_event_loop,
#if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )
ZDNwkMgr_event_loop,
#endif
zcl_event_loop,
zclSampleSw_event_loop
};
const uint8 tasksCnt = sizeof( tasksArr ) / sizeof( tasksArr[0] );
uint16 *tasksEvents;
/*********************************************************************
* FUNCTIONS
*********************************************************************/
/*********************************************************************
* @fn osalInitTasks
*
* @brief This function invokes the initialization function for each task.
*
* @param void
*
* @return none
*/
void osalInitTasks( void )
{
uint8 taskID = 0;
tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt);
osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt));
macTaskInit( taskID++ );
nwk_init( taskID++ );
Hal_Init( taskID++ );
#if defined( MT_TASK )
MT_TaskInit( taskID++ );
#endif
APS_Init( taskID++ );
#if defined ( ZIGBEE_FRAGMENTATION )
APSF_Init( taskID++ );
#endif
ZDApp_Init( taskID++ );
#if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )
ZDNwkMgr_Init( taskID++ );
#endif
zcl_Init( taskID++ );
zclSampleSw_Init( taskID );
}
/*********************************************************************
*********************************************************************/
/**************************************************************************************************
Filename: zcl_samplesw_data.c
Revised: $Date: 2008-03-11 11:01:35 -0700 (Tue, 11 Mar 2008) $
Revision: $Revision: 16570 $
Description: Zigbee Cluster Library - sample device application.
Copyright 2006-2007 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 �AS 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.
**************************************************************************************************/
/*********************************************************************
* INCLUDES
*/
#include "ZComDef.h"
#include "OSAL.h"
#include "AF.h"
#include "ZDConfig.h"
#include "zcl.h"
#include "zcl_general.h"
#include "zcl_ha.h"
#include "zcl_samplesw.h"
/*********************************************************************
* CONSTANTS
*/
#define SAMPLESW_DEVICE_VERSION 0
#define SAMPLESW_FLAGS 0
#define SAMPLESW_HWVERSION 0
#define SAMPLESW_ZCLVERSION 0
/*********************************************************************
* TYPEDEFS
*/
/*********************************************************************
* MACROS
*/
/*********************************************************************
* GLOBAL VARIABLES
*/
// Basic Cluster
const uint8 zclSampleSw_HWRevision = SAMPLESW_HWVERSION;
const uint8 zclSampleSw_ZCLVersion = SAMPLESW_ZCLVERSION;
const uint8 zclSampleSw_ManufacturerName[] = { 16, 'T','e','x','a','s','I','n','s','t','r','u','m','e','n','t','s' };
const uint8 zclSampleSw_ModelId[] = { 16, 'T','I','0','0','0','1',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' };
const uint8 zclSampleSw_DateCode[] = { 16, '2','0','0','6','0','8','3','1',' ',' ',' ',' ',' ',' ',' ',' ' };
const uint8 zclSampleSw_PowerSource = POWER_SOURCE_MAINS_1_PHASE;
uint8 zclSampleSw_LocationDescription[17] = { 16, ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' };
uint8 zclSampleSw_PhysicalEnvironment = 0;
uint8 zclSampleSw_DeviceEnable = DEVICE_ENABLED;
// Identify Cluster
uint16 zclSampleSw_IdentifyTime = 0;
// On/Off Cluster
uint8 zclSampleSw_OnOff = LIGHT_OFF;
/*********************************************************************
* ATTRIBUTE DEFINITIONS - Uses REAL cluster IDs
*/
CONST zclAttrRec_t zclSampleSw_Attrs[SAMPLESW_MAX_ATTRIBUTES] =
{
// *** General Basic Cluster Attributes ***
{
ZCL_CLUSTER_ID_GEN_BASIC, // Cluster IDs - defined in the foundation (ie. zcl.h)
{ // Attribute record
ATTRID_BASIC_HW_VERSION, // Attribute ID - Found in Cluster Library header (ie. zcl_general.h)
ZCL_DATATYPE_UINT8, // Data Type - found in zcl.h
ACCESS_CONTROL_READ, // Variable access control - found in zcl.h
(void *)&zclSampleSw_HWRevision // Pointer to attribute variable
}
},
{
ZCL_CLUSTER_ID_GEN_BASIC,
{ // Attribute record
ATTRID_BASIC_ZCL_VERSION,
ZCL_DATATYPE_UINT8,
ACCESS_CONTROL_READ,
(void *)&zclSampleSw_ZCLVersion
}
},
{
ZCL_CLUSTER_ID_GEN_BASIC,
{ // Attribute record
ATTRID_BASIC_MANUFACTURER_NAME,
ZCL_DATATYPE_CHAR_STR,
ACCESS_CONTROL_READ,
(void *)zclSampleSw_ManufacturerName
}
},
{
ZCL_CLUSTER_ID_GEN_BASIC,
{ // Attribute record
ATTRID_BASIC_MODEL_ID,
ZCL_DATATYPE_CHAR_STR,
ACCESS_CONTROL_READ,
(void *)zclSampleSw_ModelId
}
},
{
ZCL_CLUSTER_ID_GEN_BASIC,
{ // Attribute record
ATTRID_BASIC_DATE_CODE,
ZCL_DATATYPE_CHAR_STR,
ACCESS_CONTROL_READ,
(void *)zclSampleSw_DateCode
}
},
{
ZCL_CLUSTER_ID_GEN_BASIC,
{ // Attribute record
ATTRID_BASIC_POWER_SOURCE,
ZCL_DATATYPE_UINT8,
ACCESS_CONTROL_READ,
(void *)&zclSampleSw_PowerSource
}
},
{
ZCL_CLUSTER_ID_GEN_BASIC,
{ // Attribute record
ATTRID_BASIC_LOCATION_DESC,
ZCL_DATATYPE_CHAR_STR,
(ACCESS_CONTROL_READ | ACCESS_CONTROL_WRITE),
(void *)zclSampleSw_LocationDescription
}
},
{
ZCL_CLUSTER_ID_GEN_BASIC,
{ // Attribute record
ATTRID_BASIC_PHYSICAL_ENV,
ZCL_DATATYPE_UINT8,
(ACCESS_CONTROL_READ | ACCESS_CONTROL_WRITE),
(void *)&zclSampleSw_PhysicalEnvironment
}
},
{
ZCL_CLUSTER_ID_GEN_BASIC,
{ // Attribute record
ATTRID_BASIC_DEVICE_ENABLED,
ZCL_DATATYPE_UINT8,
(ACCESS_CONTROL_READ | ACCESS_CONTROL_WRITE),
(void *)&zclSampleSw_DeviceEnable
}
},
// *** Identify Cluster Attribute ***
{
ZCL_CLUSTER_ID_GEN_IDENTIFY,
{ // Attribute record
ATTRID_IDENTIFY_TIME,
ZCL_DATATYPE_UINT16,
(ACCESS_CONTROL_READ | ACCESS_CONTROL_WRITE),
(void *)&zclSampleSw_IdentifyTime
}
},
// *** On / Off Cluster Attributes ***
{
ZCL_CLUSTER_ID_GEN_ON_OFF,
{ // Attribute record
ATTRID_ON_OFF,
ZCL_DATATYPE_UINT8,
ACCESS_CONTROL_READ,
(void *)&zclSampleSw_OnOff
}
},
};
/*********************************************************************
* SIMPLE DESCRIPTOR
*/
// This is the Cluster ID List and should be filled with Application
// specific cluster IDs.
#define ZCLSAMPLESW_MAX_INCLUSTERS 1
const cId_t zclSampleSw_InClusterList[ZCLSAMPLESW_MAX_INCLUSTERS] =
{
ZCL_CLUSTER_ID_GEN_BASIC
};
#define ZCLSAMPLESW_MAX_OUTCLUSTERS 1
const cId_t zclSampleSw_OutClusterList[ZCLSAMPLESW_MAX_OUTCLUSTERS] =
{
ZCL_CLUSTER_ID_GEN_ON_OFF
};
SimpleDescriptionFormat_t zclSampleSw_SimpleDesc =
{
SAMPLESW_ENDPOINT, // int Endpoint;
ZCL_HA_PROFILE_ID, // uint16 AppProfId[2];
ZCL_HA_DEVICEID_ON_OFF_SWITCH, // uint16 AppDeviceId[2];
SAMPLESW_DEVICE_VERSION, // int AppDevVer:4;
SAMPLESW_FLAGS, // int AppFlags:4;
ZCLSAMPLESW_MAX_INCLUSTERS, // byte AppNumInClusters;
(cId_t *)zclSampleSw_InClusterList, // byte *pAppInClusterList;
ZCLSAMPLESW_MAX_OUTCLUSTERS, // byte AppNumInClusters;
(cId_t *)zclSampleSw_OutClusterList // byte *pAppInClusterList;
};
/*********************************************************************
* GLOBAL FUNCTIONS
*/
/*********************************************************************
* LOCAL FUNCTIONS
*/
/****************************************************************************
****************************************************************************/
thank you sir ... pl go through this asap ...
sir i put the lines u gave in zcl_sampleSw.c file only ...... pl refer
/**************************************************************************************************
Filename: zcl_samplesw.c
Revised: $Date: 2009-03-18 15:56:27 -0700 (Wed, 18 Mar 2009) $
Revision: $Revision: 19453 $
Description: Zigbee Cluster Library - sample device application.
Copyright 2006-2009 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 �AS 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.
*********************************************************************/
/*********************************************************************
* INCLUDES
*/
#include "ZComDef.h"
#include "OSAL.h"
#include "AF.h"
#include "ZDApp.h"
#include "ZDObject.h"
#include "ZDProfile.h"
#include "zcl.h"
#include "zcl_general.h"
#include "zcl_ha.h"
#include "zcl_samplesw.h"
#include "onboard.h"
/* HAL */
#include "hal_lcd.h"
#include "hal_led.h"
#include "hal_key.h"
/*********************************************************************
* MACROS
*/
/*********************************************************************
* CONSTANTS
*/
/*********************************************************************
* TYPEDEFS
*/
/*********************************************************************
* GLOBAL VARIABLES
*/
byte zclSampleSw_TaskID;
/*********************************************************************
* GLOBAL FUNCTIONS
*/
/*********************************************************************
* LOCAL VARIABLES
*/
static afAddrType_t zclSampleSw_DstAddr;
#define ZCLSAMPLESW_BINDINGLIST 1
static cId_t bindingOutClusters[ZCLSAMPLESW_BINDINGLIST] =
{
ZCL_CLUSTER_ID_GEN_ON_OFF
};
// Test Endpoint to allow SYS_APP_MSGs
static endPointDesc_t sampleSw_TestEp =
{
20, // Test endpoint
&zclSampleSw_TaskID,
(SimpleDescriptionFormat_t *)NULL, // No Simple description for this test endpoint
(afNetworkLatencyReq_t)0 // No Network Latency req
};
/*********************************************************************
* LOCAL FUNCTIONS
*/
static void zclSampleSw_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg );
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 );
// 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_ProcessInDiscRspCmd( zclIncomingMsg_t *pInMsg );
#endif
/*********************************************************************
* ZCL General Profile Callback table
*/
static zclGeneral_AppCallbacks_t zclSampleSw_CmdCallbacks =
{
zclSampleSw_BasicResetCB, // Basic Cluster Reset command
zclSampleSw_IdentifyCB, // Identify command
zclSampleSw_IdentifyQueryRspCB, // Identify Query Response command
NULL, // On / Off cluster command - not needed.
NULL, // Level Control Move to Level command
NULL, // Level Control Move command
NULL, // Level Control Step command
NULL, // Group Response commands
NULL, // Scene Store Request command
NULL, // Scene Recall Request command
NULL, // Scene Response commands
NULL, // Alarm (Response) commands
NULL, // RSSI Location commands
NULL, // RSSI Location Response commands
};
/*********************************************************************
* @fn zclSampleSw_Init
*
* @brief Initialization function for the zclGeneral layer.
*
* @param none
*
* @return none
*/
void zclSampleSw_Init( byte task_id )
{
zclSampleSw_TaskID = task_id;
// Set destination address to indirect
zclSampleSw_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent;
zclSampleSw_DstAddr.endPoint = 0;
zclSampleSw_DstAddr.addr.shortAddr = 0;
// 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 );
// 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 );
}
/*********************************************************************
* @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 )
{
case ZCL_INCOMING_MSG:
// Incoming ZCL Foundation command/response messages
zclSampleSw_ProcessIncomingMsg( (zclIncomingMsg_t *)MSGpkt );
break;
case ZDO_CB_MSG:
zclSampleSw_ProcessZDOMsgs( (zdoIncomingMsg_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) )
{
osal_start_timerEx( zclSampleSw_TaskID, PERIODIC_EVT , 5000 );
}
default:
break;
}
// Release the memory
osal_msg_deallocate( (uint8 *)MSGpkt );
}
// return unprocessed events
return (events ^ SYS_EVENT_MSG);
}
if ( events & PERIODIC_EVT )
{
int i=3;
if(i == 3) // check condition to send toggle command.
{
zclGeneral_SendOnOff_CmdOn( SAMPLESW_ENDPOINT, &zclSampleSw_DstAddr, false, 0 ); //Send toggle command here.
}
osal_start_timerEx( zclSampleSw_TaskID, PERIODIC_EVT , 1000 );
return ( events ^ PERIODIC_EVT);
}
/*if ( events & SAMPLESW_IDENTIFY_TIMEOUT_EVT )
{
zclSampleSw_IdentifyTime = 10;
zclSampleSw_ProcessIdentifyTimeChange();
return ( events ^ SAMPLESW_IDENTIFY_TIMEOUT_EVT );
}*/
// Discard unknown events
return 0;
}
/*********************************************************************
* @fn zclSampleSw_ProcessZDOMsgs()
*
* @brief Process response messages
*
* @param none
*
* @return none
*/
void zclSampleSw_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg )
{
switch ( inMsg->clusterID )
{
case End_Device_Bind_rsp:
if ( ZDO_ParseBindRsp( inMsg ) == ZSuccess )
{
// Light LED
HalLedSet( HAL_LED_4, HAL_LED_MODE_ON );
}
#if defined(BLINK_LEDS)
else
{
// Flash LED to show failure
HalLedSet ( HAL_LED_4, HAL_LED_MODE_FLASH );
}
#endif
break;
case Match_Desc_rsp:
{
ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( inMsg );
if ( pRsp )
{
if ( pRsp->status == ZSuccess && pRsp->cnt )
{
zclSampleSw_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
zclSampleSw_DstAddr.addr.shortAddr = pRsp->nwkAddr;
// Take the first endpoint, Can be changed to search through endpoints
zclSampleSw_DstAddr.endPoint = pRsp->epList[0];
// Light LED
HalLedSet( HAL_LED_4, HAL_LED_MODE_ON );
}
osal_mem_free( pRsp );
}
}
break;
}
}
/*********************************************************************
* @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_4
* HAL_KEY_SW_3
* HAL_KEY_SW_2
* HAL_KEY_SW_1
*
* @return none
*/
static void zclSampleSw_HandleKeys( byte shift, byte keys )
{
zAddrType_t dstAddr;
(void)shift; // Intentionally unreferenced parameter
//if ( keys & HAL_KEY_SW_1 )
/*if ( keys & HAL_KEY_SW_6 )
{
// Using this as the "Light Switch"
#ifdef ZCL_ON_OFF
zclGeneral_SendOnOff_CmdToggle( SAMPLESW_ENDPOINT, &zclSampleSw_DstAddr, false, 0 );
#endif
}*/
//if ( keys & HAL_KEY_SW_2 )
if ( keys & HAL_KEY_SW_7 )
{
HalLedSet ( HAL_LED_4, HAL_LED_MODE_ON );
// 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 );
}
if ( keys & HAL_KEY_SW_3 )
{
}
//if ( keys & HAL_KEY_SW_4 )
if ( keys & HAL_KEY_SW_8 )
{
HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF );
// Initiate a Match Description Request (Service Discovery)
dstAddr.addrMode = AddrBroadcast;
dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR;
ZDP_MatchDescReq( &dstAddr, NWK_BROADCAST_SHORTADDR,
ZCL_HA_PROFILE_ID,
ZCLSAMPLESW_BINDINGLIST, bindingOutClusters,
0, NULL, // No incoming clusters to bind
FALSE );
}
}
/*********************************************************************
* @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 )
{
}
/*********************************************************************
* @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 )
{
// Query Response (with timeout value)
(void)pRsp;
}
/******************************************************************************
*
* 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_RSP:
zclSampleSw_ProcessInDiscRspCmd( 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_ProcessInDiscRspCmd
*
* @brief Process the "Profile" Discover Response Command
*
* @param pInMsg - incoming message to process
*
* @return none
*/
static uint8 zclSampleSw_ProcessInDiscRspCmd( zclIncomingMsg_t *pInMsg )
{
zclDiscoverRspCmd_t *discoverRspCmd;
uint8 i;
discoverRspCmd = (zclDiscoverRspCmd_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
/****************************************************************************
****************************************************************************/
I see you are using SampleSwitch in Z-Stack 2.5.1a and it is obsolete. I suggest you download and install Z-Stack Home 1.2.1 and check SampleSwitch project inside.
okey sir .. i will check it out .. but may i know what is the fault the coding i maild u sir
Your merge of code is correct but zclSampleSw_NwkState only appears on latest Z-Stack. So, you have to use latest Z-Stack home to use this zclSampleSw_NwkState variable.
is it possible to use controller pgm of simpleapp to make a two way communication
i also downloaded the samples u said sir .. but unfortunately it is not at all even opening
What do you mean it is not at all even opening? Z-Stack Home 1.2.1 has to use IAR 8.30. Do you use this IAR version?
i have that previous version only sir ... so y isnt the previous example program i send is not working in the way i wanted it to sir ie. comparing a value and sending a command accordingly
OK, you can try to declare "devStates_t zclSampleSw_NwkState = DEV_INIT;" in the beginning of zcl_samplesw.c add the following case in your zclSampleSw_event_loop() after "case KEY_CHANGE:".
case ZDO_STATE_CHANGE:
devStates_t 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) )
{
osal_start_timerEx( zclSampleSw_TaskID, PERIODIC_EVT , 5000 );
}
break;
thanks a lot sir ... u r a life saver . the light in sensor node is glowing for about 20 seconds and it turnsoff and go to idle state any idea y sir ???