smart-green-house/project_ZigBee/Projects/zstack/Samples/SampleApp/Source/demoapp.c

444 lines
16 KiB
C
Raw Permalink Normal View History

2023-10-28 18:00:47 +08:00
#include "OSAL.h"
#include "ZGlobals.h"
#include "AF.h"
#include "aps_groups.h"
#include "ZDApp.h"
//#include "SampleApp.h"
#include "demoapp.h"
#include "SampleAppHw.h"
#include "OnBoard.h"
/* HAL */
#include "hal_lcd.h"
#include "hal_led.h"
#include "hal_key.h"
#include "MT_UART.h"
#include "DHT11.h"
#include "string.h"
#include "stdlib.h"
#include "MT.h"
uint8 my_TaskID;
endPointDesc_t my_epDesc;
uint8 my_TransID = 0; // This is the unique message ID (counter)
afAddrType_t my_DstAddr;
devStates_t identity_nwk = DEV_INIT;
static struct join_info join_addr[SAMPLEAPP_MAX_CLUSTERS];//<2F><><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>һ<EFBFBD><D2BB>
const cId_t my_ClusterList[SAMPLEAPP_MAX_CLUSTERS] =
{
SAMPLEAPP_SENSOR_CLUSTERID,
SAMPLEAPP_CTRL_CLUSTERID
};
//<2F>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
const SimpleDescriptionFormat_t my_SimpleDesc =
{
MY_ENDPOINT, // int Endpoint;
SAMPLEAPP_PROFID, // uint16 AppProfId[2];
SAMPLEAPP_DEVICEID, // uint16 AppDeviceId[2];
SAMPLEAPP_DEVICE_VERSION, // int AppDevVer:4;
SAMPLEAPP_FLAGS, // int AppFlags:4;
SAMPLEAPP_MAX_CLUSTERS, // uint8 AppNumInClusters;
(cId_t *)my_ClusterList, // uint8 *pAppInClusterList;
SAMPLEAPP_MAX_CLUSTERS, // uint8 AppNumInClusters;
(cId_t *)my_ClusterList // uint8 *pAppInClusterList;
};
static struct adjust_info adjust = {
TEMPS_ADJUST_MIN_DEF,
TEMPS_ADJUST_MAX_DEF,
HUMIS_ADJUST_MIN_DEF,
HUMIS_ADJUST_MAX_DEF,
TEMPS_ADJUST_MIN_DEF,
HUMIS_ADJUST_MIN_DEF,
SET_TEMP_ADJUST_CLOSE,
SET_HUMI_ADJUST_CLOSE,
MANUAL_CTRL_MODE,
MANUAL_CTRL_MODE,
5,
5};
void send_to_gateway(char *str)
{
signed char len = strlen(str);
if(len > 0){
HalUARTWrite(1,(uint8 *)str,len);
HalUARTWrite(1,"\r\n",2);
}
}
//ÿ<><C3BF><EFBFBD>ն<EFBFBD><D5B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD>ȸ<EFBFBD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><><D6BB><EFBFBD>ն˵<D5B6><CBB5><EFBFBD>
void send_coord_affirm(uint16 cid)
{
uint8 data[10];
strcpy((char *)data,CLIENT_AFFIRM);
my_DstAddr.addr.shortAddr = 0x0000;
AF_DataRequest( &my_DstAddr,//Ŀ<><C4BF><EFBFBD><EFBFBD>ַ
&my_epDesc,
cid,
strlen((char const *)data),
data,
&my_TransID,
AF_DISCV_ROUTE,
AF_DEFAULT_RADIUS );
}
//Э<><D0AD><EFBFBD><EFBFBD><EFBFBD>Բɼ<D4B2><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʪ<EFBFBD><CAAA><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>д<EFBFBD><D0B4><EFBFBD>
void coord_th_dispose(unsigned char *th)
{
char *info[10];signed char len=0;
info[len] = strtok((char *)th,",");
while(info[len]){
info[++len] = strtok(NULL,",");
}//get_data/periodic_th,24,29,open,close
if(len != 5)
return;
adjust.temp_curr = atoi((char const *)info[1]);
adjust.humi_curr = atoi((char const *)info[2]);
strcpy(adjust.temp_c_ops,info[3]);//<2F><><EFBFBD><EFBFBD><E6BFAA>״̬
strcpy(adjust.humi_c_ops,info[4]);//<2F><><EFBFBD><EFBFBD><E6BFAA>״̬
debug("<EFBFBD><EFBFBD>%d<><64><><CAAA>%d%%\n",adjust.temp_curr,adjust.humi_curr);
char tbuf[16]="";
sprintf(tbuf,"%d,%d\r",adjust.temp_curr,adjust.humi_curr);
HalUARTWrite(1,(uint8 *)tbuf,strlen(tbuf));
if(strncmp((char *)(adjust.temp_c_mode),AUTO_CTRL_MODE,strlen(AUTO_CTRL_MODE)) == 0){
if((adjust.temp_curr >= adjust.temp_min)&&(adjust.temp_curr <= adjust.temp_max)&&(strncmp(adjust.temp_c_ops,"open",strlen("open")) == 0)){
my_SendPointToPointMessage(SAMPLEAPP_SENSOR_CLUSTERID,SET_TEMP_ADJUST_CLOSE);//<2F><EFBFBD><C2B6><EFBFBD><EFBFBD><EFBFBD>,<2C>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
my_SendPointToPointMessage(SAMPLEAPP_CTRL_CLUSTERID,SET_TEMP_ADJUST_CLOSE);
}else if((adjust.temp_curr > adjust.temp_max)&&(strncmp(adjust.temp_c_ops,"close",strlen("close")) == 0)){
my_SendPointToPointMessage(SAMPLEAPP_SENSOR_CLUSTERID,SET_TEMP_ADJUST_OPEN);//<2F><EFBFBD>̫<EFBFBD><CCAB>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
my_SendPointToPointMessage(SAMPLEAPP_CTRL_CLUSTERID,SET_TEMP_ADJUST_OPEN);
}else if((adjust.temp_curr < adjust.temp_min)&&(strncmp(adjust.temp_c_ops,"close",strlen("close")) == 0)){
//<2F>¶ȹ<C2B6><C8B9><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
}
if(strncmp((char *)(adjust.humi_c_mode),AUTO_CTRL_MODE,strlen(AUTO_CTRL_MODE)) == 0){
if((adjust.humi_curr >= adjust.humi_min)&&(adjust.humi_curr <= adjust.humi_max)&&(strncmp(adjust.humi_c_ops,"open",strlen("open")) == 0)){
my_SendPointToPointMessage(SAMPLEAPP_SENSOR_CLUSTERID,SET_HUMI_ADJUST_CLOSE);//ʪ<><CAAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C>ر<EFBFBD><D8B1><EFBFBD><EFBFBD>м<EFBFBD>ʪ<EFBFBD><CAAA>ʪ<EFBFBD>
my_SendPointToPointMessage(SAMPLEAPP_CTRL_CLUSTERID,SET_HUMI_ADJUST_CLOSE);
}else if((adjust.humi_curr > adjust.humi_max)&&(strncmp(adjust.humi_c_ops,"close",strlen("close")) == 0)){
my_SendPointToPointMessage(SAMPLEAPP_SENSOR_CLUSTERID,SET_HUMI_ADJUST_OPEN);//ʪ<><CAAA>̫<EFBFBD><CCAB>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʪ<EFBFBD>
my_SendPointToPointMessage(SAMPLEAPP_CTRL_CLUSTERID,SET_HUMI_ADJUST_OPEN);
}else if((adjust.humi_curr < adjust.humi_min)&&(strncmp(adjust.humi_c_ops,"close",strlen("close")) == 0)){
//ʪ<>ȹ<EFBFBD><C8B9><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʪ<EFBFBD>
}
}
}
//<2F>ɼ<EFBFBD><C9BC><EFBFBD>ʪ<EFBFBD>Ȳ<EFBFBD><C8B2><EFBFBD><EFBFBD><EFBFBD>
void get_th_send_to_coord(char *head)
{
uint8 th[6];char curr_t[6],curr_h[6];
char temp[60],count = 100;
while(count--){
DHT11();
if((wendu_shi == 0)||(shidu_shi == 0))
continue;//<2F>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7>Ҫ<EFBFBD><D2AA><EFBFBD>²ɼ<C2B2>
else
break;
}
th[0]=wendu_shi+'0';
th[1]=wendu_ge%10+'0';
th[2]=',';
th[3]=shidu_shi+'0';
th[4]=shidu_ge%10+'0';
th[5]= 0;
if((LOCAL_LED1 == SWITCH_LED_OPEN))
strcpy(curr_t,"open");
else
strcpy(curr_t,"close");
if((LOCAL_LED2 == SWITCH_LED_OPEN))
strcpy(curr_h,"open");
else
strcpy(curr_h,"close");
sprintf(temp,"%s,%s,%s,%s",head,th,curr_t,curr_h);
debug("%s\n",temp);
my_SendPointToPointMessage(SAMPLEAPP_COORD_SEND,(uint8 *)temp);//<2F><><EFBFBD>ݸ<EFBFBD>ʽ<EFBFBD><CABD>periodic_th/get_data,25,60,open,close
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>
void serial_dispos(uint8 port,uint8 len,uint8 *str)
{
if(strstr((char *)str, GET_DATA)!=NULL){//<2F><><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>debug(uart0)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(uart1)
my_SendPointToPointMessage(SAMPLEAPP_SENSOR_CLUSTERID,GET_DATA);//Э<><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return;
}
if(port == 0){//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>
if(strncmp((char *)str,"open",strlen("open")) == 0){//<2F><><EFBFBD>Կ<EFBFBD><D4BF>ؿ<EFBFBD><D8BF>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD>
my_SendPointToPointMessage(SAMPLEAPP_SENSOR_CLUSTERID,SET_TEMP_ADJUST_OPEN);
my_SendPointToPointMessage(SAMPLEAPP_SENSOR_CLUSTERID,SET_HUMI_ADJUST_OPEN);
my_SendPointToPointMessage(SAMPLEAPP_CTRL_CLUSTERID,SET_TEMP_ADJUST_OPEN);
my_SendPointToPointMessage(SAMPLEAPP_CTRL_CLUSTERID,SET_HUMI_ADJUST_OPEN);
LOCAL_LED1 = SWITCH_LED_OPEN;
LOCAL_LED2 = SWITCH_LED_OPEN;
SWITCH_LED = SWITCH_LED_OPEN;
}else if(strncmp((char *)str,"close",strlen("close")) == 0){
my_SendPointToPointMessage(SAMPLEAPP_SENSOR_CLUSTERID,SET_TEMP_ADJUST_CLOSE);
my_SendPointToPointMessage(SAMPLEAPP_SENSOR_CLUSTERID,SET_HUMI_ADJUST_CLOSE);
my_SendPointToPointMessage(SAMPLEAPP_CTRL_CLUSTERID,SET_TEMP_ADJUST_CLOSE);
my_SendPointToPointMessage(SAMPLEAPP_CTRL_CLUSTERID,SET_HUMI_ADJUST_CLOSE);
LOCAL_LED1 = SWITCH_LED_CLOSE;
LOCAL_LED2 = SWITCH_LED_CLOSE;
SWITCH_LED = SWITCH_LED_CLOSE;
}
}else if(port == 1){//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
if(strncmp((char *)str,SET_DATA,strlen(SET_DATA)) == 0){
char *info[10];signed char len=0;
debug("%s\n",str);
info[len] = strtok((char *)str,",");
while(info[len]){
info[++len] = strtok(NULL,",");
}//set_data,24,29,40,60,auto,manual
// <20><><EFBFBD>жϺ<D0B6><CFBA><EFBFBD>ֵ
if(len != 7)
return;
adjust.temp_min = atoi(info[1]);
adjust.temp_max = atoi(info[2]);
adjust.humi_min = atoi(info[3]);
adjust.humi_max = atoi(info[4]);
strcpy((char *)(adjust.temp_c_mode),info[5]);
strcpy((char *)(adjust.humi_c_mode),info[6]);
}else if(strncmp((char *)str,SET_TEMP_ADJUST_OPEN,strlen(SET_TEMP_ADJUST_OPEN)) == 0){
if(strncmp((char *)(adjust.temp_c_mode),AUTO_CTRL_MODE,strlen(AUTO_CTRL_MODE)) == 0)
return;
strcpy(adjust.temp_c_ops,"open");
my_SendPointToPointMessage(SAMPLEAPP_SENSOR_CLUSTERID,SET_TEMP_ADJUST_OPEN);
my_SendPointToPointMessage(SAMPLEAPP_CTRL_CLUSTERID,SET_TEMP_ADJUST_OPEN);
}else if(strncmp((char *)str,SET_TEMP_ADJUST_CLOSE,strlen(SET_TEMP_ADJUST_CLOSE)) == 0){
if(strncmp((char *)(adjust.temp_c_mode),AUTO_CTRL_MODE,strlen(AUTO_CTRL_MODE)) == 0)
return;
strcpy(adjust.temp_c_ops,"close");
my_SendPointToPointMessage(SAMPLEAPP_SENSOR_CLUSTERID,SET_TEMP_ADJUST_CLOSE);
my_SendPointToPointMessage(SAMPLEAPP_CTRL_CLUSTERID,SET_TEMP_ADJUST_CLOSE);
}else if(strncmp((char *)str,SET_HUMI_ADJUST_OPEN,strlen(SET_HUMI_ADJUST_OPEN)) == 0){
if(strncmp((char *)(adjust.humi_c_mode),AUTO_CTRL_MODE,strlen(AUTO_CTRL_MODE)) == 0)
return;
strcpy(adjust.humi_c_ops,"open");
my_SendPointToPointMessage(SAMPLEAPP_SENSOR_CLUSTERID,SET_HUMI_ADJUST_OPEN);
my_SendPointToPointMessage(SAMPLEAPP_CTRL_CLUSTERID,SET_HUMI_ADJUST_OPEN);
}else if(strncmp((char *)str,SET_HUMI_ADJUST_CLOSE,strlen(SET_HUMI_ADJUST_CLOSE)) == 0){
if(strncmp((char *)(adjust.humi_c_mode),AUTO_CTRL_MODE,strlen(AUTO_CTRL_MODE)) == 0)
return;
strcpy(adjust.humi_c_ops,"close");
my_SendPointToPointMessage(SAMPLEAPP_SENSOR_CLUSTERID,SET_HUMI_ADJUST_CLOSE);
my_SendPointToPointMessage(SAMPLEAPP_CTRL_CLUSTERID,SET_HUMI_ADJUST_CLOSE);
}
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ
void my_Init( uint8 task_id )
{
my_TaskID = task_id;
MT_UartInit();//<2F><><EFBFBD>ڳ<EFBFBD>ʼ<EFBFBD><CABC>
MT_UartRegisterTaskID(task_id);//<2F>Ǽ<EFBFBD><C7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/* GPIO<49><4F>ʼ<EFBFBD><CABC> */
P1DIR |= (1<<0); //P1_0<5F><30><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
P1DIR |= (1<<1); //P1_1<5F><31><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
P2INP &= ~(1<<6);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LOCAL_LED1 = SWITCH_LED_CLOSE;
LOCAL_LED2 = SWITCH_LED_CLOSE;
P1INP &= ~(1<<3);
P1SEL &= ~((1<<0)|(1<<1)|(1<<3));
P1DIR |= (1<<0)|(1<<1)|(1<<3);
SWITCH_LED = SWITCH_LED_CLOSE;
/* <20>˵<EFBFBD><CBB5><EFBFBD>ʼ<EFBFBD><CABC> */
my_epDesc.endPoint = MY_ENDPOINT;
my_epDesc.task_id = &my_TaskID;
my_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&my_SimpleDesc;
my_epDesc.latencyReq = noLatencyReqs;
if(afRegister(&my_epDesc) == afStatus_INVALID_PARAMETER)
debug("<EFBFBD>˵<EFBFBD>ע<EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>\n");
else
debug("<EFBFBD>˵<EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>\n");
/* <20><>ַ<EFBFBD><EFBFBD><E1B9B9>ʼ<EFBFBD><CABC> */
my_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;//<2F>
my_DstAddr.endPoint = MY_ENDPOINT;
my_DstAddr.addr.shortAddr = 0x0000;//Ĭ<><C4AC>ΪЭ<CEAA><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
}
//zigbee<65><65><EFBFBD><EFBFBD>Ϣ<EFBFBD>ӿ<EFBFBD>
void my_SendPointToPointMessage(uint8 obj,uint8 *str)
{
uint16 cid;
if(identity_nwk == DEV_END_DEVICE){
my_DstAddr.addr.shortAddr = 0x0000;
cid = SAMPLEAPP_SENSOR_CLUSTERID;
}else if(identity_nwk == DEV_ZB_COORD){
if(obj == SAMPLEAPP_SENSOR_CLUSTERID){
my_DstAddr.addr.shortAddr = join_addr[SAMPLEAPP_SENSOR_CLUSTERID-1].addr;
cid = SAMPLEAPP_SENSOR_CLUSTERID;
}else if(obj == SAMPLEAPP_CTRL_CLUSTERID){
my_DstAddr.addr.shortAddr = join_addr[SAMPLEAPP_CTRL_CLUSTERID-1].addr;
cid = SAMPLEAPP_CTRL_CLUSTERID;
}
}else if(identity_nwk == DEV_ROUTER){
return;
}
debug("send:0x%x,%d\n",my_DstAddr.addr.shortAddr,cid);
AF_DataRequest( &my_DstAddr,//Ŀ<><C4BF><EFBFBD><EFBFBD>ַ
&my_epDesc,
cid,
strlen((char const *)str),
str,
&my_TransID,
AF_DISCV_ROUTE,
AF_DEFAULT_RADIUS);
}
//zigbee<65>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void my_MessageMSGCB( afIncomingMSGPacket_t *pkt )
{
uint8 data[30];
osal_memcpy(data,pkt->cmd.Data,pkt->cmd.DataLength);
data[pkt->cmd.DataLength] = 0;//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
debug("recv:%s\n",data);
switch ( pkt->clusterId )
{
case SAMPLEAPP_CTRL_CLUSTERID: //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if((identity_nwk == DEV_ZB_COORD)&&(strncmp((char *)pkt->cmd.Data,CLIENT_AFFIRM,6) == 0)){//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ն˵<D5B6>ַ
debug("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ն<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ:0x%x\n",pkt->srcAddr.addr.shortAddr);
join_addr[SAMPLEAPP_CTRL_CLUSTERID-1].type = SAMPLEAPP_CTRL_CLUSTERID;
join_addr[SAMPLEAPP_CTRL_CLUSTERID-1].addr = pkt->srcAddr.addr.shortAddr;
break;//<2F>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>˳<EFBFBD>
}else if(identity_nwk == DEV_END_DEVICE){
if(strncmp((char *)pkt->cmd.Data,SET_TEMP_ADJUST_OPEN,strlen(SET_TEMP_ADJUST_OPEN)) == 0){
SWITCH_LED = SWITCH_LED_OPEN;
}else if(strncmp((char *)pkt->cmd.Data,SET_TEMP_ADJUST_CLOSE,strlen(SET_TEMP_ADJUST_CLOSE)) == 0){
SWITCH_LED = SWITCH_LED_CLOSE;
}else if(strncmp((char *)pkt->cmd.Data,SET_HUMI_ADJUST_OPEN,strlen(SET_HUMI_ADJUST_OPEN)) == 0){
SWITCH_LED = SWITCH_LED_OPEN;
}else if(strncmp((char *)pkt->cmd.Data,SET_HUMI_ADJUST_CLOSE,strlen(SET_HUMI_ADJUST_CLOSE)) == 0){
SWITCH_LED = SWITCH_LED_CLOSE;
}
}
break;
case SAMPLEAPP_SENSOR_CLUSTERID://<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if((identity_nwk == DEV_ZB_COORD)&&(strncmp((char *)pkt->cmd.Data,CLIENT_AFFIRM,6) == 0)){//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ն˵<D5B6>ַ
debug("<EFBFBD>ɼ<EFBFBD><EFBFBD>ն<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ:0x%x\n",pkt->srcAddr.addr.shortAddr);
join_addr[SAMPLEAPP_SENSOR_CLUSTERID-1].type = SAMPLEAPP_SENSOR_CLUSTERID;
join_addr[SAMPLEAPP_SENSOR_CLUSTERID-1].addr = pkt->srcAddr.addr.shortAddr;
break;//<2F>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>˳<EFBFBD>
}else if(strncmp((char *)pkt->cmd.Data,SET_TEMP_ADJUST_OPEN,strlen(SET_TEMP_ADJUST_OPEN)) == 0){
LOCAL_LED1 = SWITCH_LED_OPEN;
SWITCH_LED = SWITCH_LED_OPEN;
}else if(strncmp((char *)pkt->cmd.Data,SET_TEMP_ADJUST_CLOSE,strlen(SET_TEMP_ADJUST_CLOSE)) == 0){
LOCAL_LED1 = SWITCH_LED_CLOSE;
SWITCH_LED = SWITCH_LED_CLOSE;
}else if(strncmp((char *)pkt->cmd.Data,SET_HUMI_ADJUST_OPEN,strlen(SET_HUMI_ADJUST_OPEN)) == 0){
LOCAL_LED2 = SWITCH_LED_OPEN;
SWITCH_LED = SWITCH_LED_OPEN;
}else if(strncmp((char *)pkt->cmd.Data,SET_HUMI_ADJUST_CLOSE,strlen(SET_HUMI_ADJUST_CLOSE)) == 0){
LOCAL_LED2 = SWITCH_LED_CLOSE;
SWITCH_LED = SWITCH_LED_CLOSE;
}else if(strncmp((char *)pkt->cmd.Data,PERIODIC_REPORT_TH,strlen(PERIODIC_REPORT_TH)) == 0){
if(identity_nwk == DEV_ZB_COORD){
coord_th_dispose(data);//periodic_th,25,60,open,close
}
}else if(strncmp((char *)pkt->cmd.Data,GET_DATA,strlen(GET_DATA)) == 0){//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(identity_nwk == DEV_END_DEVICE){//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
get_th_send_to_coord(GET_DATA);
osal_set_event(my_TaskID,DEMO_GET_TH);
}else if(identity_nwk == DEV_ZB_COORD){//Э<><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
char temp[80];
debug("%s\n",data);
//get_data,24,29,40,60,25,60,open,close,auto,manual
sprintf(temp,"%s,%d,%d,%d,%d,%s,%s,%s",GET_DATA,
adjust.temp_min,
adjust.temp_max,
adjust.humi_min,
adjust.humi_max,
data+strlen(GET_DATA)+1,//<2F><><EFBFBD><EFBFBD>"get_data,"<22>ַ<EFBFBD><><C8A1>"25,60,open,close"
adjust.temp_c_mode,
adjust.humi_c_mode
);
debug("%s\n",temp);
send_to_gateway((char *)temp);
coord_th_dispose(data);//get_data,25,60,open,close
}
}
break;
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint16 my_ProcessEvent( uint8 task_id, uint16 events )
{
afIncomingMSGPacket_t *MSGpkt = NULL;
if (events & SYS_EVENT_MSG)
{
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( my_TaskID );
while(MSGpkt != NULL){
switch ( MSGpkt->hdr.event )
{
case ZDO_STATE_CHANGE:
identity_nwk = (devStates_t)(MSGpkt->hdr.status);
if(identity_nwk == DEV_END_DEVICE){
debug("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>\n");
debug("<EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ַ=0x%x\n",NLME_GetShortAddr());
#if CTRL_OR_GATHER//<2F><><EFBFBD>ƽڵ<C6BD>/<2F>ɼ<EFBFBD><C9BC>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD>ȷ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>˭<EFBFBD><CBAD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
send_coord_affirm(SAMPLEAPP_CTRL_CLUSTERID);//<2F><><EFBFBD>Dz<EFBFBD>ͬ<EFBFBD>ն<EFBFBD>Ҫ<EFBFBD>ĵĵط<C4B5>
#else
send_coord_affirm(SAMPLEAPP_SENSOR_CLUSTERID);//<2F><><EFBFBD>Dz<EFBFBD>ͬ<EFBFBD>ն<EFBFBD>Ҫ<EFBFBD>ĵĵط<C4B5>
#endif
}
break;
case AF_INCOMING_MSG_CMD://<2F><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
my_MessageMSGCB(MSGpkt);
break;
case CMD_SERIAL_MSG:
{
uint8 str[UART_RECV_LEN];
uint8 port = *(((mtOSALSerialData_t *)MSGpkt)->msg);//<2F><><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+<2B><><EFBFBD><EFBFBD>+<2B><><EFBFBD><EFBFBD>
uint8 len = *(((mtOSALSerialData_t *)MSGpkt)->msg+1);
if(len < UART_RECV_LEN)
osal_memcpy(str,((mtOSALSerialData_t *)MSGpkt)->msg+2,len);
else
break;
if(len > 1){
*(str+len) = 0;
debug("uart%d(%d):%s\n",port,len,str);
serial_dispos(port,len,str);
}
}
break;
}
osal_msg_deallocate( (uint8 *)MSGpkt );
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive(my_TaskID);
}
return (events ^ SYS_EVENT_MSG);
}else if (events & DEMO_KEYBOARD_1){
debug("key1 down\n");
my_SendPointToPointMessage(SAMPLEAPP_SENSOR_CLUSTERID,SET_TEMP_ADJUST_OPEN);
my_SendPointToPointMessage(SAMPLEAPP_SENSOR_CLUSTERID,SET_HUMI_ADJUST_OPEN);
my_SendPointToPointMessage(SAMPLEAPP_CTRL_CLUSTERID,SET_TEMP_ADJUST_OPEN);
my_SendPointToPointMessage(SAMPLEAPP_CTRL_CLUSTERID,SET_HUMI_ADJUST_OPEN);
LOCAL_LED1 = SWITCH_LED_OPEN;
LOCAL_LED2 = SWITCH_LED_OPEN;
SWITCH_LED = SWITCH_LED_OPEN;
return (events ^ DEMO_KEYBOARD_1);
}else if (events & DEMO_KEYBOARD_2){
debug("key2 down\n");
my_SendPointToPointMessage(SAMPLEAPP_SENSOR_CLUSTERID,SET_TEMP_ADJUST_CLOSE);
my_SendPointToPointMessage(SAMPLEAPP_SENSOR_CLUSTERID,SET_HUMI_ADJUST_CLOSE);
my_SendPointToPointMessage(SAMPLEAPP_CTRL_CLUSTERID,SET_TEMP_ADJUST_CLOSE);
my_SendPointToPointMessage(SAMPLEAPP_CTRL_CLUSTERID,SET_HUMI_ADJUST_CLOSE);
LOCAL_LED1 = SWITCH_LED_CLOSE;
LOCAL_LED2 = SWITCH_LED_CLOSE;
SWITCH_LED = SWITCH_LED_CLOSE;
return (events ^ DEMO_KEYBOARD_2);
}else if (events & DEMO_GET_TH){
if(identity_nwk == DEV_END_DEVICE){
get_th_send_to_coord(PERIODIC_REPORT_TH);
osal_start_timerEx(my_TaskID,DEMO_GET_TH,SENSOR_PERIODIC_REPORTED);
}
return (events ^ DEMO_GET_TH);
}
return 0;
}