Commit a8d1c966 authored by 尹佳钦's avatar 尹佳钦

8009语音面板控制设备支持:插座,灯控,窗帘

parent 750c1fa7
......@@ -501,7 +501,7 @@ void KK_Data_FromMid(void* str,int len)
arming_status_notify(type);
}
}else{
//property_post_deal(deviceCode->valuestring,payload);
property_post_deal(deviceCode->valuestring,payload);
}
}else if(strstr(msgtype->valuestring,"/thing/topo/delete")!= NULL){
device_delete_sync(payload);
......
......@@ -36,30 +36,30 @@
static char s_ccuid[DEVICE_CODE_LEN] = {0};
int kk_lan_get_ccuid(_OU_ char *device_code)
{
strncpy(device_code, s_ccuid, strlen(s_ccuid));
printf("kk_lan_get_ccuid:%s\n",s_ccuid);
return strlen(s_ccuid);
{
strncpy(device_code, s_ccuid, strlen(s_ccuid));
printf("kk_lan_get_ccuid:%s\n",s_ccuid);
return strlen(s_ccuid);
}
static int _setDevice_Code(_IN_ char *device_code,int len)
{
memset(s_ccuid, 0x0, DEVICE_CODE_LEN);
printf("_setDevice_Code:%s\n",device_code);
strncpy(s_ccuid, device_code, len);
return len;
memset(s_ccuid, 0x0, DEVICE_CODE_LEN);
printf("_setDevice_Code:%s\n",device_code);
strncpy(s_ccuid, device_code, len);
return len;
}
extern int HAL_Execel_cmd(char * cmd,char * buf,int buf_len,int* ret_len);
static void kk_lan_ccuid_init(void)
{
uint8_t ccuid[DEVICE_CODE_LEN] = {0};
int ccuid_len = 0;
HAL_Execel_cmd(GET_CCUID_CMD,(char *)ccuid,sizeof(ccuid),&ccuid_len);
printf("GET_CCUID_CMD:%s\n",ccuid);
if(ccuid_len > 0 && ccuid_len <= DEVICE_CODE_LEN){
_setDevice_Code((char *)ccuid,ccuid_len-1);
}else{
uint8_t ccuid[DEVICE_CODE_LEN] = {0};
int ccuid_len = 0;
HAL_Execel_cmd(GET_CCUID_CMD,(char *)ccuid,sizeof(ccuid),&ccuid_len);
printf("GET_CCUID_CMD:%s\n",ccuid);
if(ccuid_len > 0 && ccuid_len <= DEVICE_CODE_LEN){
_setDevice_Code((char *)ccuid,ccuid_len-1);
}else{
_setDevice_Code(KK_CCU_ID,strlen(KK_CCU_ID));
}
}
}
......
This diff is collapsed.
......@@ -2,12 +2,34 @@
#include "kk_lan_vp_ctrl.h"
#include "cJSON.h"
cJSON *PowerSwitch_msg_build(int ep,int onoff)
{
char epNum[12] = {0};
cJSON *params = cJSON_CreateObject();
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
memset(epNum,0,sizeof(epNum));
snprintf(epNum,sizeof(epNum),"%d",ep);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON_AddStringToObject(params,"epNum",epNum);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON_AddNumberToObject(params,"PowerSwitch",onoff);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return params;
}
static int is_light_dev(int pid);
static cJSON *light_dev(int ep,int onoff);
static cJSON *light_dev_handle(int ep,uint8_t *arg);
static int is_curtain_dev(int pid);
static cJSON *curtain_dev_msg_build(int ep,int OperationMode);
static cJSON *curtain_dev_handle(int ep,uint8_t *arg);
static int is_outlet_dev(int pid);
static cJSON *outlet_msg_build(int ep,int onoff);
static cJSON *outlet_dev_handle(int ep,uint8_t *arg);
typedef int (*pid_mth_func)(int pid);
typedef cJSON *(*dev_handle)(int ep,uint8_t *arg);
......@@ -18,13 +40,24 @@ typedef struct{
}KK_VP_CTRL;
static KK_VP_CTRL vp_ctrl_table[]={
{is_light_dev,light_dev_handle}
{is_light_dev,light_dev_handle},
{is_curtain_dev,curtain_dev_handle},
{is_outlet_dev,outlet_dev_handle}
};
static int light_dev_pid[]={
3023,3024
};
static int curtain_dev_pid[]={
3067
};
static int outlet_dev_pid[]={
3020
};
static int is_light_dev(int pid)
{
int i;
......@@ -36,7 +69,53 @@ static int is_light_dev(int pid)
return 0;
}
cJSON *light_dev_msg_build(int ep,int onoff)
static int is_curtain_dev(int pid)
{
int i;
for(i=0;i<sizeof(curtain_dev_pid)/sizeof(int);i++){
if(pid==curtain_dev_pid[i]){
return 1;
}
}
return 0;
}
static int is_outlet_dev(int pid)
{
int i;
for(i=0;i<sizeof(outlet_dev_pid)/sizeof(int);i++){
if(pid==outlet_dev_pid[i]){
return 1;
}
}
return 0;
}
static cJSON *light_msg_build(int ep,int onoff)
{
return PowerSwitch_msg_build(ep,onoff);
}
static cJSON *light_dev_handle(int ep,uint8_t *arg)
{
uint8_t skill_type = arg[0];
printf("[%s][%d]skill_type=%d,ep=%d\n",__FUNCTION__,__LINE__,skill_type,ep);
switch(skill_type){
case VP_CTRL_OPEN://
return light_msg_build(ep,1);
case VP_CTRL_CLOSE:
return light_msg_build(ep,0);
default:break;
}
return NULL;
}
static cJSON *curtain_dev_msg_build(int ep,int OperationMode)
{
char epNum[12] = {0};
cJSON *params = cJSON_CreateObject();
......@@ -47,20 +126,43 @@ cJSON *light_dev_msg_build(int ep,int onoff)
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON_AddStringToObject(params,"epNum",epNum);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON_AddNumberToObject(params,"PowerSwitch",onoff);
cJSON_AddNumberToObject(params,"OperationMode",OperationMode);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return params;
}
static cJSON *light_dev_handle(int ep,uint8_t *arg)
static cJSON *curtain_dev_handle(int ep,uint8_t *arg)
{
uint8_t skill_type = arg[0];
printf("[%s][%d]skill_type=%d,ep=%d\n",__FUNCTION__,__LINE__,skill_type,ep);
switch(skill_type){
case VP_CTRL_OPEN://
return curtain_dev_msg_build(ep,1);
case VP_CTRL_CLOSE:
return curtain_dev_msg_build(ep,0);
case VP_CTRL_STOP:
return curtain_dev_msg_build(ep,2);
default:break;
}
return NULL;
}
static cJSON *outlet_msg_build(int ep,int onoff)
{
return PowerSwitch_msg_build(ep,onoff);
}
static cJSON *outlet_dev_handle(int ep,uint8_t *arg)
{
uint8_t skill_type = arg[0];
printf("[%s][%d]skill_type=%d,ep=%d\n",__FUNCTION__,__LINE__,skill_type,ep);
switch(skill_type){
case VP_CTRL_OPEN://
return light_dev_msg_build(ep,1);
return outlet_msg_build(ep,1);
case VP_CTRL_CLOSE:
return light_dev_msg_build(ep,0);
return outlet_msg_build(ep,0);
default:break;
}
return NULL;
......
......@@ -228,7 +228,7 @@ static int kk_vp_get_device_name(_IN cJSON *devices,_IN const char*epNum,_IN con
{
int i = 0,devNum = 0;
cJSON *name = NULL;
cJSON *deviceItem = NULL,*devCodeObj = NULL,*epNumObj = NULL;
cJSON *deviceItem = NULL,*devCodeObj = NULL;
devNum = cJSON_GetArraySize(devices);
printf("[%s][%d]devNum=%d\n",__FUNCTION__,__LINE__,devNum);
......@@ -239,24 +239,19 @@ static int kk_vp_get_device_name(_IN cJSON *devices,_IN const char*epNum,_IN con
continue ;
}
epNumObj = cJSON_GetObjectItem(deviceItem,"epNum");
devCodeObj = cJSON_GetObjectItem(deviceItem,"deviceCode");
if(epNumObj==NULL||epNumObj->type!=cJSON_String ||
devCodeObj==NULL||devCodeObj->type!=cJSON_String){
if(devCodeObj==NULL||devCodeObj->type!=cJSON_String){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
continue ;
}
printf("[%s][%d]%d,%d,%s,%s\n",__FUNCTION__,__LINE__,strlen(devCodeObj->valuestring),
strlen(deviceCode),devCodeObj->valuestring,deviceCode);
printf("[%s][%d]%d,%d,%s,%s\n",__FUNCTION__,__LINE__,strlen(epNumObj->valuestring),
strlen(epNum),epNumObj->valuestring,epNum);
if((strlen(devCodeObj->valuestring)==strlen(deviceCode)) &&
!strcmp(devCodeObj->valuestring,deviceCode) &&
(strlen(epNumObj->valuestring)==strlen(epNum)) &&
!strcmp(epNumObj->valuestring,epNum)){
!strcmp(devCodeObj->valuestring,deviceCode)){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if((name = cJSON_GetObjectItem(deviceItem,"name"))!=NULL &&
......
......@@ -60,7 +60,7 @@ int HAL_Execel_cmd(char * cmd,char * buf,int buf_len,int* ret_len)
}
void *HAL_Malloc(_IN_ uint32_t size)
{
return malloc(size);
return malloc(size);
}
void *HAL_Realloc(_IN_ void *ptr, _IN_ uint32_t size)
......
This diff is collapsed.
......@@ -653,10 +653,7 @@ void kk_platMsg_handle(void* data, char* chalMark){
if(jsonPay == NULL) goto error;
proCode = cJSON_GetObjectItem(jsonPay, MSG_PRODUCT_CODE_STR);
devCode = cJSON_GetObjectItem(jsonPay, MSG_DEVICE_CODE_STR);
//mac = cJSON_GetObjectItem(jsonPay, "mac");
mac = cJSON_GetObjectItem(jsonPay, MSG_DEVICE_CODE_STR);
mac = cJSON_GetObjectItem(jsonPay, "mac");
if (proCode == NULL || devCode == NULL || mac == NULL){
ERROR_PRINT("productCode, deviceCode mac params are error\n");
goto error;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment