Commit 96034b95 authored by 陈伟灿's avatar 陈伟灿

Merge branch 'cwc' into 'master'

【修改内容】修改空调内机场景的设置

See merge request chenweican/k-sdk!142
parents 4f605363 75a5620f
......@@ -22,6 +22,6 @@ typedef enum {
#define KK_DEVICESECRET_PATH "/data/kk/kk_deviceSecret.txt"
#define KK_TOKEN_PATH "/data/kk/kk_token.txt"
#define HOST_NAME "dev.nj-ikonke.site"
int KK_Get_ccuid( char *device_code);
#endif
......@@ -26,9 +26,10 @@
#include "mqtt_api.h"
#include "com_api.h"
#include "kk_product.h"
#include "kk_hal.h"
//#include "kcloud_log.h"
static char s_ccuid[DEVICE_CODE_LEN] = {0};
int KK_Get_ccuid(_OU_ char *device_code)
int KK_Get_ccuid(char *device_code)
{
strncpy(device_code, s_ccuid, strlen(s_ccuid));
printf("HAL_Get_ccuid:%s\n",s_ccuid);
......@@ -43,8 +44,8 @@ static int _setDevice_Code(_IN_ char *device_code,int len)
}
static int KK_Ccuid_init(void)
{
uint8_t ccuid[DEVICE_CODE_LEN] = {0};
uint8_t ccuidTmp[DEVICE_CODE_LEN] = {0};
char ccuid[DEVICE_CODE_LEN] = {0};
char ccuidTmp[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);
......
......@@ -332,6 +332,7 @@ int kk_start_ccu_register(void)
if(NULL == host)
{
INFO_PRINT("gethostbyname h_errno\n");
close(sockfd);
return -1;
}
memcpy(s_ServerIp,inet_ntoa(*(struct in_addr*)(host->h_addr_list[0])),strlen(inet_ntoa(*(struct in_addr*)(host->h_addr_list[0]))));
......
......@@ -217,7 +217,7 @@ extern char s_ServerIp[16];
MQTTAsync KK_MQTT_Connect(void)
{
int rc = 0;
int temp_address[128] = {0};
char temp_address[128] = {0};
FILE *fp;
MQTTAsync_createOptions opts = MQTTAsync_createOptions_initializer;
MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer;
......
......@@ -16,5 +16,6 @@ extern int KK_MQTT_UnsubTopic(const char *topicName);
extern MQTTAsync KK_MQTT_Connect(void);
int kk_get_cloud_status(void);
void kk_write_disconnect_flag(void);
#endif
......@@ -461,7 +461,8 @@ cJSON *_kk_sync_devicestatus_arg_build(kk_map_dev_node_t *node,int ch)
{
int i,num=0,n_num = 0,o_num = 0;
cJSON *newccu,*oldccu;
cJSON *arg = cJSON_CreateObject();
cJSON *arg = NULL;
int flag = 0;
if(node == NULL ||node->syn_type!=1||node->syn_opcode==NULL){
......@@ -481,7 +482,7 @@ cJSON *_kk_sync_devicestatus_arg_build(kk_map_dev_node_t *node,int ch)
num = (n_num>o_num)?o_num:n_num;
//channelNum
arg = cJSON_CreateObject();
for(i=0;i<num;i++){
cJSON * newccuItem = cJSON_GetArrayItem(newccu,i);
cJSON * oldccuItem = cJSON_GetArrayItem(oldccu,i);
......@@ -516,19 +517,24 @@ cJSON *_kk_sync_devicestatus_arg_build(kk_map_dev_node_t *node,int ch)
cJSON_AddBoolToObject(syn_obj, "enable",0);
cJSON_AddNullToObject(syn_obj, "time");
}
flag = 1;
cJSON_AddItemToObject(arg, synKey->valuestring,syn_obj);
}else{
if(atoi(newccuItemCh->valuestring)==atoi(oldccuItemCh->valuestring) &&
atoi(newccuItemCh->valuestring)==ch){
if((val = val_conver_new2old(newccuItem,oldccuItem,1))!=NULL){
flag = 1;
kk_lan_add_val_to_obj(arg,val,synKey->valuestring);
}
}
}
}
}
if(flag == 0){
cJSON_Delete(arg);
return NULL;
}
return arg;
}
......@@ -967,9 +973,12 @@ int kk_send_indoorAir_status(cJSON *info,const char *deviceCode)
return -1;
}
cJSON *root = cJSON_CreateObject();
cJSON *epNum = cJSON_GetObjectItem(info,"epNum");
cJSON *epNum = cJSON_GetObjectItem(info,"epNum");
if(epNum == NULL){
return -1;
}
cJSON *root = cJSON_CreateObject();
node = kk_lan_db_node_get(deviceCode,atoi(epNum->valuestring));
snprintf(nodeStr,sizeof(nodeStr),"%d",node);
......@@ -979,14 +988,19 @@ int kk_send_indoorAir_status(cJSON *info,const char *deviceCode)
cJSON *arg = cJSON_CreateObject();
cJSON_AddBoolToObject(arg, "online", 1);
cJSON *PowerSwitch = cJSON_GetObjectItem(info,"PowerSwitch");
if(PowerSwitch == NULL) {cJSON_Delete(root);return -1;}
cJSON_AddBoolToObject(arg, "on", PowerSwitch->valueint);
cJSON *Temperature = cJSON_GetObjectItem(info,"Temperature");
if(Temperature == NULL) {cJSON_Delete(root);return -1;}
cJSON_AddNumberToObject(arg,"settingTemperature",Temperature->valuedouble);
cJSON *CurrentTemperature = cJSON_GetObjectItem(info,"CurrentTemperature");
if(CurrentTemperature == NULL) {cJSON_Delete(root);return -1;}
cJSON_AddNumberToObject(arg,"roomTemperature",CurrentTemperature->valuedouble);
cJSON *WindSpeed = cJSON_GetObjectItem(info,"WindSpeed");
if(WindSpeed == NULL) {cJSON_Delete(root);return -1;}
cJSON_AddStringToObject(arg, "fanSpeed", speedMap[WindSpeed->valueint]);
cJSON *WorkMode = cJSON_GetObjectItem(info,"WorkMode");
if(WorkMode == NULL) {cJSON_Delete(root);return -1;}
cJSON_AddStringToObject(arg, "runModel", modeMap[WorkMode->valueint]);
cJSON_AddItemToObject(root, "arg", arg);
......
......@@ -153,6 +153,7 @@ int kk_msg_execute_scene_delete(const char* params,const char *fatherDeviceCode)
int dm_msg_thing_syncinfo_reply(void);
int dm_msg_thing_syncinfopush_reply(void);
void kk_split(char *src,const char *separator,char **dest,int *num);
int kk_msg_cloud_status_notify(const char *deviceCode,const char *productCode);
//const char DM_URI_SYS_PREFIX[] DM_READ_ONLY = "/sys/%s/%s/";
......
......@@ -590,7 +590,7 @@ static productype_map_s producTypeMap[] = {
{"LIGHT_STRIP","colorDimmableLight"},
{"LIGHT_DIMMER","lightPanel"},
{"SOCKET","outlet"},
{"AC_IndoorUnit","airConditioning"},
{"AC_IndoorUnit","air conditioning gateway"},
{"FLOOR_HEATING","floorHeating"},
{"FRESH_AIR","freshAir"},
{"AIR_SWITCH","airSwitch"},
......@@ -599,6 +599,59 @@ int kk_get_product_type_table_size(void)
{
return sizeof(producTypeMap)/sizeof(productype_map_s);
}
static int _kk_indoor_air_info_handle(char* deviceCode,char* propertyName,char* propertyValue,int ep,int delay,char* gwDeviceCode,char*sceneId,char* type)
{
int res = 0;
kk_scene_action_detail_t info = {0};
memcpy(info.deviceCode,deviceCode,strlen(deviceCode));
memcpy(info.propertyName,propertyName,strlen(propertyName));
memcpy(info.propertyValue,propertyValue,strlen(propertyValue));
info.epNum = ep;
info.delay = delay;
kk_scene_action_add(gwDeviceCode,sceneId,info);
res = kk_scene_insert_scene_action(type,deviceCode,info.epNum,
propertyName,propertyValue,info.delay,sceneId,gwDeviceCode);
if(res != SUCCESS_RETURN){
INFO_PRINT("kk_subDev_set_action_by_productType fail!!!\n");
}
return res;
}
static int _kk_indoor_air_handle(char* deviceCode, char *sceneId, char *propertyName, char *propertyValue, char *type,int delay, char*gwDeviceCode)
{
int eplist[64] = {0};
char data[32] = {0};
int res = 0;
int i = 0;
int count = kk_indoorAir_query_epnums(deviceCode,eplist);
for(i = 0; i < count; i++){
if(strcmp(propertyName,"CustomAction") == 0){
cJSON* json = cJSON_Parse(propertyValue);
if (json == NULL) {
return -1;
}
cJSON* Temperature = cJSON_GetObjectItem(json, "Temperature");
if(Temperature == NULL) { cJSON_Delete(json);return -1;}
memset(data,0x0,sizeof(data));
sprintf(data,"%f",Temperature->valuedouble);
_kk_indoor_air_info_handle(deviceCode,"Temperature",data,eplist[i],delay,gwDeviceCode,sceneId,type);
cJSON* WindSpeed = cJSON_GetObjectItem(json, "WindSpeed");
if(WindSpeed == NULL) { cJSON_Delete(json);return -1;}
memset(data,0x0,sizeof(data));
sprintf(data,"%d",WindSpeed->valueint);
_kk_indoor_air_info_handle(deviceCode,"WindSpeed",data,eplist[i],delay,gwDeviceCode,sceneId,type);
cJSON* WorkMode = cJSON_GetObjectItem(json, "WorkMode");
if(WorkMode == NULL){ cJSON_Delete(json);return -1;}
memset(data,0x0,sizeof(data));
sprintf(data,"%d",WorkMode->valueint);
_kk_indoor_air_info_handle(deviceCode,"WorkMode",data,eplist[i],delay,gwDeviceCode,sceneId,type);
cJSON_Delete(json);
}else{
_kk_indoor_air_info_handle(deviceCode,propertyName,propertyValue,eplist[i],delay,gwDeviceCode,sceneId,type);
}
}
return 0;
}
int kk_subDev_set_action_by_productType(const char *productType,const char *sceneId,const char *propertyName,const char *propertyValue,const char *type,int delay)
{
int res = 0;
......@@ -609,7 +662,7 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *scen
kk_subDb_ctx_t *ctx = _kk_subDb_get_ctx();
const char *searchCmd = "select * from SubDeviceInfo WHERE productType= '%s'";
int idx = 0;
int gw_support_scene = 0;
//int gw_support_scene = 0;
kk_tsl_data_t *property = NULL;
int k = 0,count = 0;
char typeArray[10][32] = {0};
......@@ -635,7 +688,7 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *scen
}
}
for(k = 0; k < count; k++){
//printf("---------------------------->typeArray[k]:%s\n",typeArray[k]);
INFO_PRINT("typeArray[k]:%s\n",typeArray[k]);
sqlCmd = sqlite3_mprintf(searchCmd,typeArray[k]); //curtain type
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
//INFO_PRINT("total_column = %d\n", sqlite3_column_count(stmt));
......@@ -645,12 +698,18 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *scen
if (res != SUCCESS_RETURN) {
continue;
}
if(strcmp(typeArray[k],"air conditioning gateway") == 0){
_kk_indoor_air_handle(pDeviceCode,sceneId,propertyName,propertyValue,type,delay,node->fatherDeviceCode);
continue;
}
#if 0
if(kk_subDev_check_scene_support(node->fatherDeviceCode) == 1){
gw_support_scene = 1;
}
else{
gw_support_scene = 0;
}
#endif
//if(!strcmp(typeArray[k],"switch")){
for(idx = 0; idx < node->dev_shadow->property_number; idx++){
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
......@@ -659,7 +718,7 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *scen
}
char *ptr = strstr(property->identifier,propertyName);
if(ptr != NULL && (ptr-property->identifier==0) ){
if(gw_support_scene){
//if(gw_support_scene){
kk_scene_action_detail_t info = {0};
memcpy(info.deviceCode,node->deviceCode,strlen(node->deviceCode));
memcpy(info.propertyName,property->identifier,strlen(property->identifier));
......@@ -681,7 +740,7 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *scen
//return res;
continue;
}
}
//}
}
}
......
......@@ -666,6 +666,8 @@ static int kk_indoorAir_property_save(cJSON *payload,char *deviceCode)
while(client_list != NULL){
cJSON *epNum = cJSON_GetObjectItem(client_list, "epNum");
if(epNum == NULL){
client_list = client_list->next;
// printf("-----------------------------------------------------------------------222\n");
continue;
}
if(epNum->type == cJSON_Number){
......@@ -676,6 +678,7 @@ static int kk_indoorAir_property_save(cJSON *payload,char *deviceCode)
for(idx = 0; idx < node->dev_shadow->property_number; idx++){
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
if(property == NULL){
client_list = client_list->next;
continue;
}
propertyItem = cJSON_GetObjectItem(client_list, property->identifier);
......
......@@ -809,7 +809,7 @@ static int _kk_tsl_get_service_input_value(_IN_ kk_tsl_t * dev_shadow, _IN_ char
return FAIL_RETURN;
}
res = (data, &type);
res = kk_tsl_get_data_type(data, &type);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......
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