Commit 0ebddec5 authored by chen.weican's avatar chen.weican

【修改内容】修改一系列问题

【提交人】陈伟灿
parent 82aa5a66
...@@ -193,6 +193,30 @@ static int kk_split_send_data(cJSON *pData,const char* topic) ...@@ -193,6 +193,30 @@ static int kk_split_send_data(cJSON *pData,const char* topic)
return RETURN_SUCCESS; return RETURN_SUCCESS;
} }
char * g_filerToCloudTable[] =
{
(char *){"/thing/service/historyAlarm_reply"},
(char *){"/thing/service/delAlarm_reply"},
};
/************************************************************
*功能描述:过滤不需要下发给网关的消息
*输入参数:msgtype:消息类型
*输出参数:无
*返 回 值:1:过滤;0:不过滤
*其他说明:
*************************************************************/
static int _kk_filter_to_cloud(const char* msgtype)
{
int i = 0,num = 0;
num = sizeof(g_filerToCloudTable)/sizeof(char *);
for(i =0; i < num; i++){
if(strstr(msgtype,g_filerToCloudTable[i]))
{
return 1;
}
}
return 0;
}
/************************************************************ /************************************************************
*功能描述:上报数据给云端 *功能描述:上报数据给云端
*输入参数: root:所上报数据 *输入参数: root:所上报数据
...@@ -214,7 +238,10 @@ int _kk_sendto_cloud(cJSON *root) ...@@ -214,7 +238,10 @@ int _kk_sendto_cloud(cJSON *root)
if(msgTypeStr == NULL){ if(msgTypeStr == NULL){
return RETURN_FAIL; return RETURN_FAIL;
} }
if(_kk_filter_to_cloud(msgTypeStr->valuestring)){
INFO_PRINT(" this msg do not send to cloud!!!\n");
return RETURN_FAIL;
}
pData = cJSON_GetObjectItem(root, MSG_PAYLOAD_STR); pData = cJSON_GetObjectItem(root, MSG_PAYLOAD_STR);
if(pData == NULL){ if(pData == NULL){
free(topic); free(topic);
......
...@@ -208,6 +208,7 @@ static char * kk_create_register_info() ...@@ -208,6 +208,7 @@ static char * kk_create_register_info()
uint8_t productSecret[64] = {0}; uint8_t productSecret[64] = {0};
char ccuid[32] = {0}; char ccuid[32] = {0};
int productSecret_len = 0; int productSecret_len = 0;
char keyTmp[64] = {0};
root=cJSON_CreateObject(); root=cJSON_CreateObject();
HAL_Get_mac(mac); HAL_Get_mac(mac);
HAL_GetTime_s(ramdonId); HAL_GetTime_s(ramdonId);
...@@ -219,7 +220,8 @@ static char * kk_create_register_info() ...@@ -219,7 +220,8 @@ static char * kk_create_register_info()
if(productSecret_len == 0){ if(productSecret_len == 0){
utils_hmac_sha256((const uint8_t *)signSource, strlen(signSource), (const uint8_t *)PRODUCTSECRET, strlen(PRODUCTSECRET), sign_hex); utils_hmac_sha256((const uint8_t *)signSource, strlen(signSource), (const uint8_t *)PRODUCTSECRET, strlen(PRODUCTSECRET), sign_hex);
}else{ }else{
utils_hmac_sha256((const uint8_t *)signSource, strlen(signSource), (const uint8_t *)productSecret, strlen((const char*)productSecret), sign_hex); memcpy(keyTmp,productSecret,productSecret_len-1);
utils_hmac_sha256((const uint8_t *)signSource, strlen(signSource), (const uint8_t *)keyTmp, strlen((const char*)keyTmp), sign_hex);
} }
arrayToStr(sign_hex,32,sign_hex_str); arrayToStr(sign_hex,32,sign_hex_str);
......
...@@ -395,9 +395,7 @@ static int kk_parse_syncinfo(cJSON *payload) ...@@ -395,9 +395,7 @@ static int kk_parse_syncinfo(cJSON *payload)
cJSON * newccuItem; cJSON * newccuItem;
cJSON *valuejson; cJSON *valuejson;
int value; int value;
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_map_dev_deinit(); kk_map_dev_deinit();
...@@ -428,13 +426,9 @@ static int kk_parse_syncinfo(cJSON *payload) ...@@ -428,13 +426,9 @@ static int kk_parse_syncinfo(cJSON *payload)
properties = cJSON_GetObjectItem(subitem,MSG_PROPERTIES_STR); properties = cJSON_GetObjectItem(subitem,MSG_PROPERTIES_STR);
kk_map_dev_node_add(deviceCode,productCode,gwdevicecode,(onlineStatus->valueint==1)?"1":"0"); kk_map_dev_node_add(deviceCode,productCode,gwdevicecode,(onlineStatus->valueint==1)?"1":"0");
kk_lan_property_post_deal(deviceCode,properties); kk_lan_property_post_deal(deviceCode,properties);
//property_syn_deal(deviceCode,properties);
subitem = subitem->next; subitem = subitem->next;
} }
} }
...@@ -523,27 +517,19 @@ typedef struct{ ...@@ -523,27 +517,19 @@ typedef struct{
}alarmcontext_map_s; }alarmcontext_map_s;
static alarmcontext_map_s alarmContext[] = { static alarmcontext_map_s alarmContext[] = {
{"3049","检测到有人 告警时间戳"}, {"3049","检测到有人 告警时间戳"},
{"WINDOW","actuator"}, {"3054","SOS 按钮触发报警 告警时间戳"},
{"LIGHT","switch"}, {"3083","检测到浓雾 告警时间戳"},
{"LIGHT_STRIP","colorDimmableLight"}, {"3051","检测到有开关门 告警时间戳"},
{"LIGHT_DIMMER","lightPanel"},
{"SOCKET","outlet"},
{"AC_IndoorUnit","air"},
{"FLOOR_HEATING","floorHeating"},
{"FRESH_AIR","airConditioning"},
{"AIR_SWITCH","airSwitch"},
}; };
static alarmcontext_map_s lowbatteryContext[] = { static alarmcontext_map_s lowbatteryContext[] = {
{"3049","人体感应设备电量低 告警时间戳"}, {"3049","人体感应设备电量低 告警时间戳"},
{"WINDOW","actuator"}, {"3054","SOS按钮电量低 告警时间戳"},
{"LIGHT","switch"}, {"3083","烟感电量低 告警时间戳"},
{"LIGHT_STRIP","colorDimmableLight"}, {"3051","门磁电量低 告警时间戳"},
{"LIGHT_DIMMER","lightPanel"}, };
{"SOCKET","outlet"}, static alarmcontext_map_s DismantleStateContext[] = {
{"AC_IndoorUnit","air"}, {"3083","烟感被拆除 告警时间戳"},
{"FLOOR_HEATING","floorHeating"},
{"FRESH_AIR","airConditioning"},
{"AIR_SWITCH","airSwitch"},
}; };
int kk_get_alarmcontext_type_table_size(void) int kk_get_alarmcontext_type_table_size(void)
{ {
...@@ -553,6 +539,10 @@ int kk_get_lowbattery_table_size(void) ...@@ -553,6 +539,10 @@ int kk_get_lowbattery_table_size(void)
{ {
return sizeof(lowbatteryContext)/sizeof(alarmcontext_map_s); return sizeof(lowbatteryContext)/sizeof(alarmcontext_map_s);
} }
int kk_get_DismantleState_table_size(void)
{
return sizeof(DismantleStateContext)/sizeof(alarmcontext_map_s);
}
static cJSON * kk_device_alarm_build(char *key,char *context,char *deviceCode) static cJSON * kk_device_alarm_build(char *key,char *context,char *deviceCode)
{ {
int nodeId = 0; int nodeId = 0;
...@@ -580,7 +570,6 @@ static int kk_device_alarm_handle(cJSON *payload,char * productid,char *deviceCo ...@@ -580,7 +570,6 @@ static int kk_device_alarm_handle(cJSON *payload,char * productid,char *deviceCo
for(k = 0; k < size; k++){ for(k = 0; k < size; k++){
//printf("---------------------------->producTypeMap[k].type:%s\n",producTypeMap[k].type); //printf("---------------------------->producTypeMap[k].type:%s\n",producTypeMap[k].type);
if(!strcmp(productid,alarmContext[k].productId)){ if(!strcmp(productid,alarmContext[k].productId)){
printf("------------------------------>/thing/event/alarmNotify 111\n");
root = kk_device_alarm_build(key,alarmContext[k].msg,deviceCode); root = kk_device_alarm_build(key,alarmContext[k].msg,deviceCode);
send_msg_to_module(root); send_msg_to_module(root);
cJSON_Delete(root); cJSON_Delete(root);
...@@ -601,6 +590,19 @@ static int kk_device_alarm_handle(cJSON *payload,char * productid,char *deviceCo ...@@ -601,6 +590,19 @@ static int kk_device_alarm_handle(cJSON *payload,char * productid,char *deviceCo
} }
} }
} }
cJSON *DismantleState = cJSON_GetObjectItem(params, "DismantleState");
if(DismantleState != NULL){
size = kk_get_DismantleState_table_size();
for(k = 0; k < size; k++){
//printf("---------------------------->producTypeMap[k].type:%s\n",producTypeMap[k].type);
if(!strcmp(productid,DismantleStateContext[k].productId)){
root = kk_device_alarm_build(key,DismantleStateContext[k].msg,deviceCode);
send_msg_to_module(root);
cJSON_Delete(root);
return 0;
}
}
}
} }
return -1; return -1;
} }
...@@ -610,7 +612,6 @@ static int _timer_conver(char *buffer,time_t itime) ...@@ -610,7 +612,6 @@ static int _timer_conver(char *buffer,time_t itime)
struct tm *info; struct tm *info;
info = localtime(&itime ); info = localtime(&itime );
strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", info); strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", info);
printf("格式化的日期 & 时间 : |%s|\n", buffer );
return(0); return(0);
} }
static int kk_device_historyalarm_handle(cJSON *payload) static int kk_device_historyalarm_handle(cJSON *payload)
...@@ -659,7 +660,18 @@ static int kk_device_historyalarm_handle(cJSON *payload) ...@@ -659,7 +660,18 @@ static int kk_device_historyalarm_handle(cJSON *payload)
break; break;
} }
} }
}else{ }else if(strcmp(identifier->valuestring,"DismantleState") == 0){
size = kk_get_DismantleState_table_size();
for(k = 0; k < size; k++){
//printf("---------------------------->producTypeMap[k].type:%s\n",producTypeMap[k].type);
if(!strcmp(productCodeJ->valuestring,DismantleStateContext[k].productId)){
cJSON_AddStringToObject(infoItem, "alarm_msg", DismantleStateContext[k].msg);
break;
}
}
}
else{
size = kk_get_alarmcontext_type_table_size(); size = kk_get_alarmcontext_type_table_size();
for(k = 0; k < size; k++){ for(k = 0; k < size; k++){
//printf("---------------------------->producTypeMap[k].type:%s\n",producTypeMap[k].type); //printf("---------------------------->producTypeMap[k].type:%s\n",producTypeMap[k].type);
......
...@@ -156,7 +156,30 @@ err: ...@@ -156,7 +156,30 @@ err:
return NULL; return NULL;
} }
static kk_map_dev_node_t *kk_map_dev_node_create_ex(const char *deviceCode,const char *productCode,const char *gwdeviceCode,
const char *onlineStatus)
{
kk_map_dev_node_t *node = NULL;
cJSON *json = NULL;
cJSON *newccu = NULL,*oldccu = NULL,*channel = NULL,*optype = NULL;
cJSON *syn_type = NULL,*syn_opcode = NULL;
printf("kk_map_dev_node_create\n");
node = malloc(sizeof(kk_map_dev_node_t));
if (node == NULL) {
return NULL;
}
memset(node,0x0,sizeof(kk_map_dev_node_t));
node->json = NULL;
memcpy(node->gwDeviceCode,gwdeviceCode,strlen(gwdeviceCode));
memcpy(node->deviceCode,deviceCode,strlen(deviceCode));
memcpy(node->productCode,productCode,strlen(productCode));
node->online_status = (strcmp(onlineStatus,"1")==0)?1:0;
node->channelNum = 0;
node->newccu = NULL;
node->oldccu = NULL;
return node;
}
static char *kk_open_lan_cfg_file(char *deviceCode) static char *kk_open_lan_cfg_file(char *deviceCode)
...@@ -406,7 +429,6 @@ int kk_map_dev_search_by_deviceCode(char *deviceCode, kk_map_dev_node_t **node) ...@@ -406,7 +429,6 @@ int kk_map_dev_search_by_deviceCode(char *deviceCode, kk_map_dev_node_t **node)
{ {
kk_map_dev_ctx *ctx = _kk_map_dev_ctx(); kk_map_dev_ctx *ctx = _kk_map_dev_ctx();
kk_map_dev_node_t *search_node = NULL; kk_map_dev_node_t *search_node = NULL;
kk_map_dev_node_t *n = NULL;
//list_for_each_entry_safe //list_for_each_entry_safe
list_for_each_entry(search_node, &ctx->dev_list, linked_list, kk_map_dev_node_t) { list_for_each_entry(search_node, &ctx->dev_list, linked_list, kk_map_dev_node_t) {
...@@ -425,7 +447,25 @@ int kk_map_dev_search_by_deviceCode(char *deviceCode, kk_map_dev_node_t **node) ...@@ -425,7 +447,25 @@ int kk_map_dev_search_by_deviceCode(char *deviceCode, kk_map_dev_node_t **node)
ERROR_PRINT("Device Not Found, deviceCode: %s\n", deviceCode); ERROR_PRINT("Device Not Found, deviceCode: %s\n", deviceCode);
return -1; return -1;
} }
int kk_map_dev_search_by_productCode(char *productCode, kk_map_dev_node_t **node)
{
kk_map_dev_ctx *ctx = _kk_map_dev_ctx();
kk_map_dev_node_t *search_node = NULL;
//list_for_each_entry_safe
list_for_each_entry(search_node, &ctx->dev_list, linked_list, kk_map_dev_node_t) {
if ( (strlen(search_node->productCode) == strlen(productCode)) &&
(memcmp(search_node->productCode, productCode, strlen(productCode)) == 0)) {
/* dm_log_debug("Device Found, devid: %d", devid); */
if (node) {
*node = search_node;
}
printf("[find]%s\n",search_node->productCode);
return 0;
}
}
ERROR_PRINT("Device Not Found, productCode: %s\n", productCode);
return -1;
}
kk_map_dev_node_t *kk_map_dev_node_add(const char *deviceCode,const char *productCode,const char *gwdeviceCode,const char *onlineStatus) kk_map_dev_node_t *kk_map_dev_node_add(const char *deviceCode,const char *productCode,const char *gwdeviceCode,const char *onlineStatus)
...@@ -444,11 +484,14 @@ kk_map_dev_node_t *kk_map_dev_node_add(const char *deviceCode,const char *produc ...@@ -444,11 +484,14 @@ kk_map_dev_node_t *kk_map_dev_node_add(const char *deviceCode,const char *produc
_kk_map_dev_mutex_lock(); _kk_map_dev_mutex_lock();
if((buf = kk_open_lan_cfg_file(productCode))!=NULL){ if((buf = kk_open_lan_cfg_file(productCode))!=NULL){
node = kk_map_dev_node_create(deviceCode,productCode,gwdeviceCode,onlineStatus,buf); node = kk_map_dev_node_create(deviceCode,productCode,gwdeviceCode,onlineStatus,buf);
}else{
node = kk_map_dev_node_create_ex(deviceCode,productCode,gwdeviceCode,onlineStatus);
}
if(node){ if(node){
INIT_LIST_HEAD(&node->linked_list); INIT_LIST_HEAD(&node->linked_list);
list_add_tail(&node->linked_list, &ctx->dev_list); list_add_tail(&node->linked_list, &ctx->dev_list);
} }
}
_kk_map_dev_mutex_unlock(); _kk_map_dev_mutex_unlock();
return node; return node;
......
...@@ -37,4 +37,5 @@ int mac_switchto_deviceCode(char *mac,char * deviceCode); ...@@ -37,4 +37,5 @@ int mac_switchto_deviceCode(char *mac,char * deviceCode);
int kk_map_dev_search_by_deviceCode(char *deviceCode, kk_map_dev_node_t **node); int kk_map_dev_search_by_deviceCode(char *deviceCode, kk_map_dev_node_t **node);
kk_map_dev_ctx *_kk_map_dev_ctx(void); kk_map_dev_ctx *_kk_map_dev_ctx(void);
int kk_map_dev_init(void); int kk_map_dev_init(void);
int kk_map_dev_search_by_productCode(char *productCode, kk_map_dev_node_t **node);
#endif #endif
...@@ -116,11 +116,59 @@ cJSON * kk_control_protocol_convert(kk_map_dev_node_t *devNode,int nodeId,cJSON ...@@ -116,11 +116,59 @@ cJSON * kk_control_protocol_convert(kk_map_dev_node_t *devNode,int nodeId,cJSON
return params; return params;
} }
static int kk_indoorAir_ctrl_handle(char *epNum,cJSON *arg)
{
kk_map_dev_node_t *dev = NULL;
if(arg == NULL || epNum == NULL){
return -1;
}
char deviceCode[33]={0};
cJSON *root = cJSON_CreateObject();
cJSON *params = cJSON_CreateObject();
cJSON_AddStringToObject(params,"epNum",epNum);
cJSON *on = cJSON_GetObjectItem(arg,"on");
if(on == NULL) return -1;
cJSON_AddNumberToObject(params,"PowerSwitch",on->valueint);
cJSON *fanSpeed = cJSON_GetObjectItem(arg,"fanSpeed");
if(fanSpeed == NULL) return -1;
if(strcmp(fanSpeed->valuestring,"HIGH") == 0){
cJSON_AddNumberToObject(params,"WindSpeed",4);
}else if(strcmp(fanSpeed->valuestring,"MID") == 0){
cJSON_AddNumberToObject(params,"WindSpeed",3);
}else if(strcmp(fanSpeed->valuestring,"LOW") == 0){
cJSON_AddNumberToObject(params,"WindSpeed",2);
}else{
cJSON_AddNumberToObject(params,"WindSpeed",0);
}
cJSON *settingTemperature = cJSON_GetObjectItem(arg,"settingTemperature");
if(settingTemperature == NULL) return -1;
cJSON_AddNumberToObject(params,"Temperature",settingTemperature->valuedouble);
cJSON *runModel = cJSON_GetObjectItem(arg,"runModel");
if(runModel == NULL) return -1;
if(strcmp(runModel->valuestring,"COLD") == 0){
cJSON_AddNumberToObject(params,"WorkMode",1);
}else if(strcmp(runModel->valuestring,"HOT") == 0){
cJSON_AddNumberToObject(params,"WorkMode",2);
}else if(strcmp(runModel->valuestring,"AIR_SUPPLY") == 0){
cJSON_AddNumberToObject(params,"WorkMode",3);
}else if(strcmp(runModel->valuestring,"AUTO") == 0){
cJSON_AddNumberToObject(params,"WorkMode",0);
}else if(strcmp(runModel->valuestring,"DEHUMIDIFICATION") == 0){
cJSON_AddNumberToObject(params,"WorkMode",4);
}else{
cJSON_AddNumberToObject(params,"WorkMode",0);
}
if(kk_map_dev_search_by_productCode("3062", &dev)!=0){
printf("kk_indoorAir_ctrl_handle get deviceCode error!!!");
return -1;
}
cJSON *info = property_info_build("/thing/service/property/set","3062",dev->deviceCode);
cJSON *payload = property_payload_build("thing.service.property.set","1","v1.0",params);
cJSON_AddItemToObject(root,INFO_STRING,info);
cJSON_AddItemToObject(root,PAYLOAD_STRING,payload);
kk_ipc_send_json(root);
return 0;
}
int kk_ccu_opcode_handle(cJSON *root) int kk_ccu_opcode_handle(cJSON *root)
{ {
...@@ -133,8 +181,6 @@ int kk_ccu_opcode_handle(cJSON *root) ...@@ -133,8 +181,6 @@ int kk_ccu_opcode_handle(cJSON *root)
char deviceCode[33]={0}; char deviceCode[33]={0};
kk_map_dev_node_t *dev; kk_map_dev_node_t *dev;
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
nodeId = cJSON_GetObjectItem(root,NODEID_STR); nodeId = cJSON_GetObjectItem(root,NODEID_STR);
opcode = cJSON_GetObjectItem(root,OPCODE_STR); opcode = cJSON_GetObjectItem(root,OPCODE_STR);
arg = cJSON_GetObjectItem(root,ARG_STR); arg = cJSON_GetObjectItem(root,ARG_STR);
...@@ -151,6 +197,12 @@ int kk_ccu_opcode_handle(cJSON *root) ...@@ -151,6 +197,12 @@ int kk_ccu_opcode_handle(cJSON *root)
if(requester!=NULL){ if(requester!=NULL){
WARNING_PRINT("[requester]%s\n",requester->valuestring); WARNING_PRINT("[requester]%s\n",requester->valuestring);
if(strcmp(requester->valuestring,"HJ_CentralAC") == 0 &&
strcmp(opcode->valuestring,"CENTRAL_AC_INDOOR_UNIT_SETTING") == 0){
kk_indoorAir_ctrl_handle(nodeId->valuestring,arg);
return 0;
}
} }
kk_lan_db_deviceCode_get(atoi(nodeId->valuestring),deviceCode); kk_lan_db_deviceCode_get(atoi(nodeId->valuestring),deviceCode);
......
...@@ -123,8 +123,9 @@ static cJSON * _new_device_build(void* arg) ...@@ -123,8 +123,9 @@ static cJSON * _new_device_build(void* arg)
cJSON_AddStringToObject(dev,"mac",item->mac); cJSON_AddStringToObject(dev,"mac",item->mac);
cJSON_AddStringToObject(dev,"nodeid",item->nodeid); cJSON_AddStringToObject(dev,"nodeid",item->nodeid);
cJSON_AddStringToObject(dev,"operate_type",item->operate_type); cJSON_AddStringToObject(dev,"operate_type",item->operate_type);
cJSON_AddStringToObject(dev,"gw_mac",item->gw_mac); cJSON_AddStringToObject(dev,"gw_mac",item->gwmac);
cJSON_AddStringToObject(dev,"status",item->status); cJSON_AddStringToObject(dev,"status","");
//printf("------------------CWC------------------------>[%s][%d]\n",__FUNCTION__,__LINE__);
return dev; return dev;
} }
static cJSON * _new_hue_light_build(void* arg) static cJSON * _new_hue_light_build(void* arg)
...@@ -252,9 +253,16 @@ static cJSON * _new_central_ac_gw_indoor_build(void* arg) ...@@ -252,9 +253,16 @@ static cJSON * _new_central_ac_gw_indoor_build(void* arg)
cJSON *dev = cJSON_CreateObject(); cJSON *dev = cJSON_CreateObject();
CENTRAL_AC_INDOOR_ITEM* item=arg; CENTRAL_AC_INDOOR_ITEM* item=arg;
cJSON_AddStringToObject(dev,"id",item->id); cJSON_AddStringToObject(dev,"id",item->id);
cJSON_AddStringToObject(dev,"bind_central_ac_gw_node_id",item->bind_central_ac_gw_node_id); cJSON_AddStringToObject(dev,"indooruint_addr",item->indooruint_addr);
cJSON_AddStringToObject(dev,"ac_gw_status",item->ac_gw_status); cJSON_AddStringToObject(dev,"bind_central_ac_gw_node_id",item->nodeid);
cJSON *status = cJSON_CreateObject();
cJSON_AddBoolToObject(status,"on",item->ac_gw_status.on);
cJSON_AddBoolToObject(status,"online",item->ac_gw_status.online);
cJSON_AddNumberToObject(status,"roomTemperature",item->ac_gw_status.roomTemperature);
cJSON_AddNumberToObject(status,"settingTemperature",item->ac_gw_status.settingTemperature);
cJSON_AddStringToObject(status,"runModel",item->ac_gw_status.mode);
cJSON_AddStringToObject(status,"fanSpeed",item->ac_gw_status.speed);
cJSON_AddItemToObject(dev,"status",status);
return dev; return dev;
} }
...@@ -287,7 +295,7 @@ cJSON *new_device_notify_msg_build(NEW_DEVICE_NOTIFY *info) ...@@ -287,7 +295,7 @@ cJSON *new_device_notify_msg_build(NEW_DEVICE_NOTIFY *info)
cJSON *msg; cJSON *msg;
if(info==NULL){ if(info==NULL){
return ; return NULL;
} }
arg = cJSON_CreateObject(); arg = cJSON_CreateObject();
...@@ -325,15 +333,56 @@ cJSON *new_device_notify_msg_build(NEW_DEVICE_NOTIFY *info) ...@@ -325,15 +333,56 @@ cJSON *new_device_notify_msg_build(NEW_DEVICE_NOTIFY *info)
return msg; return msg;
} }
extern new_dev_item g_new_item[16];
extern int g_newgw_count;
void ttttt_test() extern int g_indoor_count;
extern CENTRAL_AC_INDOOR_ITEM *g_indoor_item;
static cJSON *new_devices_build_gw(int count)
{
int i = 0;
cJSON *ary = cJSON_CreateArray();
for(i = 0; i < count; i++){
cJSON *dev = cJSON_CreateObject();
cJSON_AddStringToObject(dev,"channel",g_new_item[i].channel);
cJSON_AddStringToObject(dev,"mac",g_new_item[i].mac);
cJSON_AddStringToObject(dev,"nodeid",g_new_item[i].nodeid);
cJSON_AddStringToObject(dev,"operate_type",g_new_item[i].operate_type);
cJSON_AddStringToObject(dev,"gw_mac",g_new_item[i].gwmac);
cJSON_AddStringToObject(dev,"status","");
cJSON_AddItemToArray(ary,dev);
}
return ary;
}
static cJSON *new_devices_build_indoor(int count)
{ {
int i = 0;
cJSON *ary = cJSON_CreateArray();
for(i = 0 ; i < count; i++){
cJSON *dev = cJSON_CreateObject();
cJSON_AddStringToObject(dev,"id",g_indoor_item[i].id);
cJSON_AddStringToObject(dev,"indooruint_addr",g_indoor_item[i].indooruint_addr);
cJSON_AddStringToObject(dev,"bind_central_ac_gw_node_id",g_indoor_item[i].nodeid);
cJSON *status = cJSON_CreateObject();
cJSON_AddBoolToObject(status,"on",g_indoor_item[i].ac_gw_status.on);
cJSON_AddBoolToObject(status,"online",g_indoor_item[i].ac_gw_status.online);
cJSON_AddNumberToObject(status,"roomTemperature",g_indoor_item[i].ac_gw_status.roomTemperature);
cJSON_AddNumberToObject(status,"settingTemperature",g_indoor_item[i].ac_gw_status.settingTemperature);
cJSON_AddStringToObject(status,"runModel",g_indoor_item[i].ac_gw_status.mode);
cJSON_AddStringToObject(status,"fanSpeed",g_indoor_item[i].ac_gw_status.speed);
cJSON_AddItemToObject(dev,"status",status);
cJSON_AddItemToArray(ary,dev);
}
return ary;
}
void kk_new_device_send()
{
char tmp[4] = {0};
NEW_DEVICE_NOTIFY info; NEW_DEVICE_NOTIFY info;
cJSON *msg; cJSON *msg;
info.new_device_count = cJSON_CreateString("0"); sprintf(tmp,"%d",g_newgw_count);
info.new_devices = new_devices_build(NEW_DEVICES_BUILD_TYPE,0,NULL); info.new_device_count = cJSON_CreateString(tmp);
info.new_devices = new_devices_build_gw(g_newgw_count);
info.new_hue_lights_count = cJSON_CreateString("0"); info.new_hue_lights_count = cJSON_CreateString("0");
...@@ -365,19 +414,18 @@ void ttttt_test() ...@@ -365,19 +414,18 @@ void ttttt_test()
info.new_central_ac_gws_count = cJSON_CreateString("0"); info.new_central_ac_gws_count = cJSON_CreateString("0");
info.new_central_ac_gws = new_devices_build(NEW_CENTRAL_AC_GWS_BUILD_TYPE,0,NULL); info.new_central_ac_gws = new_devices_build(NEW_CENTRAL_AC_GWS_BUILD_TYPE,0,NULL);
//printf("------------------CWC------------------------>[%s][%d]\n",__FUNCTION__,__LINE__);
info.new_central_ac_indoorunits_count = cJSON_CreateString("0"); memset(tmp,0x0,sizeof(tmp));
info.new_central_ac_indoorunits = new_devices_build(NEW_CENTRAL_AC_GW_INDOORS_BUILD_TYPE,0,NULL); sprintf(tmp,"%d",g_indoor_count);
info.new_central_ac_indoorunits_count = cJSON_CreateString(tmp);
info.new_central_ac_indoorunits = new_devices_build_indoor(g_indoor_count);
info.new_youzhuan_music_controllers_count = cJSON_CreateString("0"); info.new_youzhuan_music_controllers_count = cJSON_CreateString("0");
info.new_youzhuan_music_controllers = new_devices_build(NEW_YOUZHUAN_MUSIC_CONTROLLERS_BUILD_TYPE,0,NULL); info.new_youzhuan_music_controllers = new_devices_build(NEW_YOUZHUAN_MUSIC_CONTROLLERS_BUILD_TYPE,0,NULL);
msg = new_device_notify_msg_build(&info); msg = new_device_notify_msg_build(&info);
send_msg_to_module(msg);
printf("\n\n----------------------------------->%s\n\n",cJSON_Print(msg)); cJSON_Delete(msg);
kk_clear_indoor_data();
} }
......
#ifndef __KK_LAN_NEW_DEV_NOTIFY_H #ifndef __KK_LAN_NEW_DEV_NOTIFY_H
#define __KK_LAN_NEW_DEV_NOTIFY_H #define __KK_LAN_NEW_DEV_NOTIFY_H
#include "kk_ccu_msg.h" #include "kk_ccu_msg.h"
#include <stdbool.h>
typedef struct { typedef struct {
cJSON *new_device_count; cJSON *new_device_count;
cJSON *new_devices; cJSON *new_devices;
...@@ -46,12 +46,11 @@ typedef struct { ...@@ -46,12 +46,11 @@ typedef struct {
typedef struct{ typedef struct{
char *channel; char channel[4];
char *mac; char mac[32];
char *nodeid; char gwmac[32];
char *operate_type; char operate_type[12];
char *gw_mac; char nodeid[8];
char *status;
}new_dev_item; }new_dev_item;
typedef struct{ typedef struct{
...@@ -126,11 +125,20 @@ typedef struct{ ...@@ -126,11 +125,20 @@ typedef struct{
char *ac_gw_status; char *ac_gw_status;
}CENTRAL_AC_ITEM; }CENTRAL_AC_ITEM;
typedef struct{
bool online;
bool on;
char mode[16];
char speed[16];
double settingTemperature;
double roomTemperature;
}CENTRAL_AC_INDOOR_STATUS;
typedef struct{ typedef struct{
char *id; char id[4];
char *bind_central_ac_gw_node_id; char indooruint_addr[4];
char *ac_gw_status; char nodeid[8];
CENTRAL_AC_INDOOR_STATUS ac_gw_status;
}CENTRAL_AC_INDOOR_ITEM; }CENTRAL_AC_INDOOR_ITEM;
......
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
#include "kk_ccu_msg.h" #include "kk_ccu_msg.h"
#include "kk_lan_sync.h" #include "kk_lan_sync.h"
#include "kk_lan_debug.h" #include "kk_lan_debug.h"
#include "kk_lan_node_db.h"
#include "kk_lan_new_dev_notify.h"
/*******获取同步数据json*******/ /*******获取同步数据json*******/
...@@ -96,7 +97,7 @@ static cJSON *_kk_scene_action_build(SYN_SCENE_ACTION *act) ...@@ -96,7 +97,7 @@ static cJSON *_kk_scene_action_build(SYN_SCENE_ACTION *act)
if(ptr->nodeid==-1 || ptr->operation==NULL || if(ptr->nodeid==-1 || ptr->operation==NULL ||
ptr->operation==NULL){ ptr->operation==NULL){
return ; return NULL;
} }
cJSON *action = cJSON_CreateObject(); cJSON *action = cJSON_CreateObject();
cJSON_AddStringToObject(action, "area",(ptr->ui_area==NULL)?"":ptr->ui_area); cJSON_AddStringToObject(action, "area",(ptr->ui_area==NULL)?"":ptr->ui_area);
...@@ -331,6 +332,10 @@ int _kk_sync_device_item(cJSON *deviceCode,cJSON *epNum,cJSON *name,cJSON *roomI ...@@ -331,6 +332,10 @@ int _kk_sync_device_item(cJSON *deviceCode,cJSON *epNum,cJSON *name,cJSON *roomI
if (node != NULL) { if (node != NULL) {
if(strlen(node->deviceCode)==strlen(deviceCode->valuestring) && if(strlen(node->deviceCode)==strlen(deviceCode->valuestring) &&
!strcmp(node->deviceCode,deviceCode->valuestring)){ !strcmp(node->deviceCode,deviceCode->valuestring)){
//空调内机不放入devices
if(strcmp(node->productCode,"3062") == 0){
continue;
}
cJSON *subdevicesItem = cJSON_CreateObject(); cJSON *subdevicesItem = cJSON_CreateObject();
if(epNum==NULL ||epNum->type!=cJSON_String){ if(epNum==NULL ||epNum->type!=cJSON_String){
...@@ -415,7 +420,7 @@ int kk_sync_devices_to_sdk(cJSON *root,cJSON *data) ...@@ -415,7 +420,7 @@ int kk_sync_devices_to_sdk(cJSON *root,cJSON *data)
} }
cJSON_AddItemToObject(root, DEVICES_STRING, deviceAry); cJSON_AddItemToObject(root, DEVICES_STRING, deviceAry);
return root; return 0;
} }
...@@ -617,7 +622,7 @@ cJSON *kk_sync_gw_version_to_sdk(cJSON *root,cJSON *data) ...@@ -617,7 +622,7 @@ cJSON *kk_sync_gw_version_to_sdk(cJSON *root,cJSON *data)
cJSON *gw_version = cJSON_CreateArray(); cJSON *gw_version = cJSON_CreateArray();
int i,gw_num; int i,gw_num;
if(devicesAry->type!=cJSON_Array){ if(devicesAry->type!=cJSON_Array){
return ; return NULL;
} }
gw_num = cJSON_GetArraySize(devicesAry); gw_num = cJSON_GetArraySize(devicesAry);
...@@ -787,48 +792,189 @@ cJSON *_kk_sync_central_ac_gw(SYN_CENTRAL_AC_GW *gw) ...@@ -787,48 +792,189 @@ cJSON *_kk_sync_central_ac_gw(SYN_CENTRAL_AC_GW *gw)
return item; return item;
} }
cJSON *_kk_sync_central_acs_gw(int num,SYN_CENTRAL_AC_GW *gws) static int kk_get_roomInfo_by_deviceCode(cJSON *data,char *pdeviceCode,char*roomId)
{ {
int i; cJSON *rooms = cJSON_GetObjectItem(data,"rooms");
cJSON *central_ac_gws = cJSON_CreateArray(); cJSON * item = rooms->child;
SYN_CENTRAL_AC_GW *gw = gws; while(item != NULL){
cJSON *devices = cJSON_GetObjectItem(item,"devices");
for(i=0;i<num;i++,gw++) { if(devices == NULL){
cJSON *item =_kk_sync_central_ac_gw(gw); return -1;
cJSON_AddItemToArray(central_ac_gws,item); }
cJSON * subitem = devices->child;
while(subitem != NULL){
cJSON *deviceCode = cJSON_GetObjectItem(subitem,"deviceCode");
if(deviceCode != NULL && !strcmp(deviceCode->valuestring,pdeviceCode))
{
cJSON *roomIdJ = cJSON_GetObjectItem(item,"roomId");
memcpy(roomId,roomIdJ->valuestring,strlen(roomIdJ->valuestring));
}
return 0;
}
} }
return central_ac_gws; return -1;
}
new_dev_item g_new_item[16] = {0};
CENTRAL_AC_INDOOR_ITEM *g_indoor_item = NULL;
int g_newgw_count = 0;
int g_indoor_count = 0;
void kk_clear_indoor_data()
{
memset(g_new_item,0x0,sizeof(new_dev_item)*16);
if(g_indoor_item != NULL){
free(g_indoor_item);
g_indoor_item = NULL;
}
g_newgw_count = 0;
g_indoor_count = 0;
}
void kk_create_new_central_ac(char *gwDeviceCode,char *deviceCode,char *nodeId)
{
char gwmac[32] = {0};
char submac[32] = {0};
if(g_newgw_count > 16){
return;
}
//printf("------------------CWC------------------------>[%s][%d]\n",__FUNCTION__,__LINE__);
_deviceCode_switchto_mac(gwDeviceCode,gwmac);
_deviceCode_switchto_mac(deviceCode,submac);
memcpy(g_new_item[g_newgw_count].gwmac,gwmac,strlen(gwmac));
memcpy(g_new_item[g_newgw_count].mac,submac,strlen(submac));
memcpy(g_new_item[g_newgw_count].channel,"1",strlen("1"));
memcpy(g_new_item[g_newgw_count].operate_type,"12001",strlen("12001"));
memcpy(g_new_item[g_newgw_count].nodeid,nodeId,strlen(nodeId));
g_newgw_count++;
//printf("------------------CWC------------------------>[%s][%d]\n",__FUNCTION__,__LINE__);
return;
} }
int kk_sync_indoor_status(cJSON* eps){
}
char *modeMap[] = {
"AUTO",
"COLD",
"HOT",
"AIR_SUPPLY",
"DEHUMIDIFICATION",
"UNKONWN"
};
char *speedMap[] = {
"AUTO",
"UNKONWN",
"LOW",
"MID",
"HIGH",
"UNKONWN",
"UNKONWN",
};
int kk_send_indoorAir_status(cJSON *info)
{
char epStr[4] = {0};
if(info == NULL){
return -1;
}
cJSON *root = cJSON_CreateObject();
cJSON *epNum = cJSON_GetObjectItem(info,"epNum");
cJSON_AddStringToObject(root, "nodeid", epNum->valuestring);
cJSON_AddStringToObject(root, "opcode", "CENTRAL_AC_INDOOR_UNIT_STATUS");
cJSON_AddStringToObject(root, "status", "success");
cJSON *arg = cJSON_CreateObject();
cJSON_AddBoolToObject(arg, "online", 1);
cJSON *PowerSwitch = cJSON_GetObjectItem(info,"PowerSwitch");
cJSON_AddBoolToObject(arg, "on", PowerSwitch->valueint);
cJSON *Temperature = cJSON_GetObjectItem(info,"Temperature");
cJSON_AddNumberToObject(arg,"settingTemperature",Temperature->valuedouble);
cJSON *CurrentTemperature = cJSON_GetObjectItem(info,"CurrentTemperature");
cJSON_AddNumberToObject(arg,"roomTemperature",CurrentTemperature->valuedouble);
cJSON *WindSpeed = cJSON_GetObjectItem(info,"WindSpeed");
cJSON_AddStringToObject(arg, "fanSpeed", speedMap[WindSpeed->valueint]);
cJSON *WorkMode = cJSON_GetObjectItem(info,"WorkMode");
cJSON_AddStringToObject(arg, "runModel", modeMap[WorkMode->valueint]);
cJSON_AddItemToObject(root, "arg", arg);
send_msg_to_module(root);
cJSON_Delete(root);
return 0;
}
cJSON *kk_sync_central_ac_to_sdk(cJSON *root,cJSON *data) cJSON *kk_sync_central_ac_to_sdk(cJSON *root,cJSON *data)
{ {
int gw_num = 0,i = 0;
cJSON *central_ac_gws; int sub_num = 0,j = 0;
int k = 0;
char nodeid[8] = {0};
char roomId[32] = {0};
char deviceName[256] = {0};
char epStr[4] = {0};
cJSON *central_ac_gws = cJSON_CreateArray();
SYN_CENTRAL_AC_GW ac; SYN_CENTRAL_AC_GW ac;
ac.dev_name = malloc(20); if(data == NULL){
memset(ac.dev_name,0,20); return NULL;
memcpy(ac.dev_name,"空调网关",sizeof("空调网关")); }
kk_clear_indoor_data();
ac.node = malloc(20); cJSON *gwAry = cJSON_GetObjectItem(data,DEVICES_STR);
memset(ac.node,0,20); if(gwAry == NULL) return NULL;
memcpy(ac.node,"80",sizeof("80")); gw_num = cJSON_GetArraySize(gwAry);
for(i = 0; i < gw_num; i++){
ac.id = malloc(20); cJSON *gwitem = cJSON_GetArrayItem(gwAry,i);
memset(ac.id,0,20); cJSON *gwDeviceCode = cJSON_GetObjectItem(gwitem,"deviceCode");
memcpy(ac.id,"11",sizeof("11")); if(gwitem == NULL) return NULL;
cJSON *subAry = cJSON_GetObjectItem(gwitem,DEVICES_STR);
ac.room_id = malloc(20); if(subAry == NULL) return NULL;
memset(ac.room_id,0,20); sub_num = cJSON_GetArraySize(subAry);
memcpy(ac.room_id,"22",sizeof("22")); for(j = 0; j < sub_num; j++){
cJSON *subitem = cJSON_GetArrayItem(subAry,j);
ac.status = cJSON_CreateObject(); if(subitem == NULL) return NULL;
cJSON *productCode = cJSON_GetObjectItem(subitem,"productCode");
if(productCode != NULL && strcmp(productCode->valuestring,"3062") == 0){//空调网关设备
central_ac_gws = _kk_sync_central_acs_gw(1,&ac); cJSON *deviceCode = cJSON_GetObjectItem(subitem,"deviceCode");
kk_creater_nodeid(deviceCode->valuestring,1,nodeid);
cJSON *properties = cJSON_GetObjectItem(subitem,"properties");
cJSON *indoorItem = cJSON_CreateObject();
kk_get_roomInfo_by_deviceCode(data,deviceCode->valuestring,roomId);
cJSON_AddStringToObject(indoorItem, "bind_central_ac_gw_node_id",nodeid);
cJSON_AddStringToObject(indoorItem, "dev_name", "空调网关");
cJSON_AddStringToObject(indoorItem, "id", nodeid);
cJSON_AddStringToObject(indoorItem, "room_id", roomId);
cJSON_AddItemToArray(central_ac_gws,indoorItem);
cJSON *epsAry = cJSON_GetObjectItem(properties,"eps");
cJSON *EpTotal = cJSON_GetObjectItem(properties,"EpTotal");
int epsize = cJSON_GetArraySize(epsAry);
g_indoor_item = (CENTRAL_AC_INDOOR_ITEM *)malloc(sizeof(CENTRAL_AC_INDOOR_ITEM)*epsize);
if(g_indoor_item == NULL){
return NULL;
}
memset(g_indoor_item,0x0,sizeof(CENTRAL_AC_INDOOR_ITEM)*epsize);
g_indoor_count = epsize;
for(k = 0; k < epsize; k++){
char tmpIdx[4] = {0};
cJSON *infoItem = cJSON_GetArrayItem(epsAry,k);
if(infoItem == NULL) continue;
cJSON *epNum = cJSON_GetObjectItem(infoItem,"epNum");
memset(epStr,0x0,sizeof(epStr));
sprintf(epStr,"%d",epNum->valueint);
memcpy(g_indoor_item[k].id,epStr,strlen(epStr));
sprintf(tmpIdx,"%d",k);
memcpy(g_indoor_item[k].indooruint_addr,tmpIdx,strlen(tmpIdx));
memcpy(g_indoor_item[k].nodeid,nodeid,strlen(nodeid));
cJSON *PowerSwitch = cJSON_GetObjectItem(infoItem,"PowerSwitch");
g_indoor_item[k].ac_gw_status.on = PowerSwitch->valueint == 1?true:false;
g_indoor_item[k].ac_gw_status.online = 1;
cJSON *Temperature = cJSON_GetObjectItem(infoItem,"Temperature");
cJSON *CurrentTemperature = cJSON_GetObjectItem(infoItem,"CurrentTemperature");
g_indoor_item[k].ac_gw_status.settingTemperature = Temperature->valuedouble;
g_indoor_item[k].ac_gw_status.roomTemperature = CurrentTemperature->valuedouble;
cJSON *WindSpeed = cJSON_GetObjectItem(infoItem,"WindSpeed");
memcpy(g_indoor_item[k].ac_gw_status.speed,speedMap[WindSpeed->valueint],strlen(speedMap[WindSpeed->valueint]));
cJSON *WorkMode = cJSON_GetObjectItem(infoItem,"WorkMode");
memcpy(g_indoor_item[k].ac_gw_status.mode,modeMap[WorkMode->valueint],strlen(modeMap[WorkMode->valueint]));
}
kk_create_new_central_ac(gwDeviceCode->valuestring,deviceCode->valuestring,nodeid);
}
}
}
cJSON_AddItemToObject(root, "central_ac_gws", central_ac_gws); cJSON_AddItemToObject(root, "central_ac_gws", central_ac_gws);
return root;
} }
//同步空调网关内机 //同步空调网关内机
...@@ -1140,11 +1286,19 @@ int kk_create_syncinfo_to_sdk(cJSON *payload) ...@@ -1140,11 +1286,19 @@ int kk_create_syncinfo_to_sdk(cJSON *payload)
#endif #endif
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
char *out=cJSON_Print(root);
printf("out:%s\n",out);
cJSON *msg = old_ccu_msg_build_json("*","SYNC_INFO",NULL,root); cJSON *msg = old_ccu_msg_build_json("*","SYNC_INFO",NULL,root);
send_msg_to_module(msg); send_msg_to_module(msg);
cJSON_Delete(msg); cJSON_Delete(msg);
free(out);
if(g_indoor_count > 0){
sleep(1);
kk_new_device_send();
}
return 0; return 0;
} }
......
...@@ -9,7 +9,7 @@ typedef struct{ ...@@ -9,7 +9,7 @@ typedef struct{
char *room_id; char *room_id;
char *room_icon; char *room_icon;
char *room_name; char *room_name;
cJSON *room_status; char *room_status;
}SYN_ROOM_ITEM; }SYN_ROOM_ITEM;
...@@ -47,7 +47,7 @@ int kk_sync_devices_status_to_sdk(cJSON *root); ...@@ -47,7 +47,7 @@ int kk_sync_devices_status_to_sdk(cJSON *root);
int kk_create_syncinfo_to_sdk(cJSON *payload); int kk_create_syncinfo_to_sdk(cJSON *payload);
int kk_send_indoorAir_status(cJSON *info);
......
...@@ -54,14 +54,12 @@ static int _kk_handle_data(char *buf,int sockfd){ ...@@ -54,14 +54,12 @@ static int _kk_handle_data(char *buf,int sockfd){
if(buf == NULL){ if(buf == NULL){
return -1; return -1;
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
pStart = strstr(buf, "!"); pStart = strstr(buf, "!");
pEnd = strstr(buf, "$"); pEnd = strstr(buf, "$");
if(pStart != NULL && pEnd != NULL){ if(pStart != NULL && pEnd != NULL){
memset(tmpBuf,0x0,sizeof(tmpBuf)); memset(tmpBuf,0x0,sizeof(tmpBuf));
memcpy(tmpBuf,pStart+1,(pEnd - pStart - 1)); memcpy(tmpBuf,pStart+1,(pEnd - pStart - 1));
} }
debug_log(LOG_NORMAL,"[recv]%s\n",tmpBuf);
json=cJSON_Parse(tmpBuf); json=cJSON_Parse(tmpBuf);
if (!json) { if (!json) {
WARNING_PRINT("Error before: [%s]\n","cJSON_Parse"); WARNING_PRINT("Error before: [%s]\n","cJSON_Parse");
...@@ -206,6 +204,7 @@ void *TCPServer() ...@@ -206,6 +204,7 @@ void *TCPServer()
if(ret > 0) if(ret > 0)
{ {
printf("recv->buf:%s\n",Buf);
_kk_handle_data(Buf,s_ConnInfo[index].socketfd); _kk_handle_data(Buf,s_ConnInfo[index].socketfd);
} }
else else
......
...@@ -98,7 +98,6 @@ cJSON * val_conver_new2old(cJSON *newccuItem,cJSON *oldccuItem,int syn_type) ...@@ -98,7 +98,6 @@ cJSON * val_conver_new2old(cJSON *newccuItem,cJSON *oldccuItem,int syn_type)
}else{ }else{
o_dataType = cJSON_GetObjectItem(oldccuItem,DATATYPE_STRING); o_dataType = cJSON_GetObjectItem(oldccuItem,DATATYPE_STRING);
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return ccu_value_convert(n_dataType,n_valueRange,o_dataType,o_valueRange,n_value); return ccu_value_convert(n_dataType,n_valueRange,o_dataType,o_valueRange,n_value);
} }
...@@ -397,7 +396,25 @@ static int kk_lan_property_convert(const char *deviceCode,kk_map_dev_node_t *dev ...@@ -397,7 +396,25 @@ static int kk_lan_property_convert(const char *deviceCode,kk_map_dev_node_t *dev
return 0; return 0;
} }
static int attr_indoorAir_report(cJSON *params)
{
int k = 0;
if(params == NULL){
return -1;
}
cJSON *epsAry = cJSON_GetObjectItem(params,"eps");
if(epsAry == NULL){
return -1;
}
int epsize = cJSON_GetArraySize(epsAry);
for(k = 0; k < epsize; k++){
char tmpIdx[4] = {0};
cJSON *infoItem = cJSON_GetArrayItem(epsAry,k);
if(infoItem == NULL) continue;
kk_send_indoorAir_status(infoItem);
}
return 0;
}
//属性状态上报处理 //属性状态上报处理
int kk_lan_property_post_deal(const char *deviceCode,cJSON *payload) int kk_lan_property_post_deal(const char *deviceCode,cJSON *payload)
{ {
...@@ -408,7 +425,12 @@ int kk_lan_property_post_deal(const char *deviceCode,cJSON *payload) ...@@ -408,7 +425,12 @@ int kk_lan_property_post_deal(const char *deviceCode,cJSON *payload)
if(kk_map_dev_search_by_deviceCode(deviceCode, &dev)==0){ if(kk_map_dev_search_by_deviceCode(deviceCode, &dev)==0){
params = cJSON_GetObjectItem(payload,"params"); params = cJSON_GetObjectItem(payload,"params");
if(strcmp(dev->productCode,"3062") == 0){
attr_indoorAir_report(params);
}else{
return kk_lan_property_convert(deviceCode,dev,params); return kk_lan_property_convert(deviceCode,dev,params);
}
}else{ }else{
debug_log(LOG_DEBUG,"[err] not find deviceCode(%s).\n",deviceCode); debug_log(LOG_DEBUG,"[err] not find deviceCode(%s).\n",deviceCode);
return -1; return -1;
......
...@@ -869,99 +869,6 @@ void exit_subboard_test_ack(pro_data_t pro_data) ...@@ -869,99 +869,6 @@ void exit_subboard_test_ack(pro_data_t pro_data)
#endif #endif
} }
void set_sn_ack(pro_data_t pro_data)
{
unsigned char sn_str[128] = {0};
pro_data_t pro_data_tmp;
//uint8_t arg_buf[256];
memset((char*)&pro_data_tmp,0,sizeof(pro_data_t));
memcpy(&pro_data_tmp,&pro_data,sizeof(pro_data_t));
//pro_data_tmp.arg = arg_buf;
memcpy(pro_data_tmp.arg,pro_data.arg,pro_data.args_len);
pro_data_tmp.cf.dir = 1;
pro_data_tmp.cf.sof_flag = 0;
//pro_data_tmp.arg[pro_data_tmp.args_len++] = 0; // err status
uint8_t sn_len = pro_data_tmp.arg[0];
int i = 0;
for(i = 0; i < sn_len; i++)
{
sn_str[i] = pro_data_tmp.arg[i+1];
}
sn_str[i]='\0';
printf("sn_str:%s\n",sn_str);
pro_data_tmp.arg[0] = 0; // err status
memset(&pro_data_tmp.arg[1],0,pro_data_tmp.args_len);
memcpy(&pro_data_tmp.arg[1],&pro_data.arg[0],pro_data.args_len);
pro_data_tmp.args_len++;
uint8_t data_buf[255] = {0};
uint8_t data_len = 0;
char buf[64] = {0};
int ret_len = 0;
char cmd[128] = {0};
sprintf(cmd,"%s%s",SET_SN_CMD,sn_str);
kk_execel_cmd(cmd,buf,64,&ret_len);
//save_cfg_str_to_file(SN_CFG_FILE,(char *)sn_str);
data_len = proto_frame_to_uart(&pro_data_tmp,data_buf);
dev_send_uart(data_buf, data_len);
}
void get_sn_ack(pro_data_t pro_data)
{
pro_data_t pro_data_tmp;
memset((char*)&pro_data_tmp,0,sizeof(pro_data_t));
memcpy(&pro_data_tmp,&pro_data,sizeof(pro_data_t));
pro_data_tmp.cf.dir = 1;
pro_data_tmp.cf.sof_flag = 0;
//pro_data_tmp.arg[pro_data_tmp.args_len++] = 0; // err status
//��־λд��
uint8_t sn[128] = {0};
int sn_len = 0;
kk_execel_cmd(GET_SN_CMD,(char *)sn,128,&sn_len);
//int sn_len = strlen((char *)sn);
pro_data_tmp.args_len = 0;
if(sn_len == 0)
{
pro_data_tmp.arg[pro_data_tmp.args_len++] = 1; // err status
}
else
{
pro_data_tmp.arg[pro_data_tmp.args_len++] = 0; // err status
}
sn_len--;//ȥ�����з�
pro_data_tmp.arg[pro_data_tmp.args_len++] = sn_len; // version len
memcpy(&pro_data_tmp.arg[pro_data_tmp.args_len],(char *)sn,sn_len);
pro_data_tmp.args_len += sn_len;
uint8_t data_buf[255] = {0};
uint8_t data_len = 0;
data_len = proto_frame_to_uart(&pro_data_tmp,data_buf);
dev_send_uart(data_buf, data_len);
}
/********************/ /********************/
extern void kk_vp_opcode_handle(pro_data_t *pro_data); extern void kk_vp_opcode_handle(pro_data_t *pro_data);
...@@ -1007,18 +914,6 @@ void uart_frame_handle() ...@@ -1007,18 +914,6 @@ void uart_frame_handle()
break; break;
} }
case OPCODE_SET_SN:
{
set_sn_ack(pro_data);
break;
}
case OPCODE_GET_SN:
{
get_sn_ack(pro_data);
break;
}
case OPCODE_READ_VERSION: case OPCODE_READ_VERSION:
{ {
read_version_ack(pro_data); read_version_ack(pro_data);
......
...@@ -548,7 +548,6 @@ out: ...@@ -548,7 +548,6 @@ out:
if (fp) { if (fp) {
fclose(fp); fclose(fp);
} }
return result; return result;
} }
...@@ -753,7 +752,6 @@ uint32_t HAL_Get_IP(char ip_str[NETWORK_ADDR_LEN], const char *ifname) ...@@ -753,7 +752,6 @@ uint32_t HAL_Get_IP(char ip_str[NETWORK_ADDR_LEN], const char *ifname)
strncpy(ip_str, strncpy(ip_str,
inet_ntoa(((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr), inet_ntoa(((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr),
NETWORK_ADDR_LEN); NETWORK_ADDR_LEN);
return ((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr.s_addr; return ((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr.s_addr;
} }
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#define SN_ADDR_LEN (32+1) #define SN_ADDR_LEN (32+1)
#define PRODUCT_TPYE "kk" #define PRODUCT_TPYE "kk"
#define CCU_LAN "eth1" #define CCU_LAN "eth0"
#define KK_CCU_ID "CCU_77771" #define KK_CCU_ID "CCU_77771"
#define KK_CCU_PRODUCTID "ccu_n12" #define KK_CCU_PRODUCTID "ccu_n12"
#define KK_GW_PRODUCTID "gateway_2" #define KK_GW_PRODUCTID "gateway_2"
......
...@@ -308,7 +308,33 @@ ERROR: ...@@ -308,7 +308,33 @@ ERROR:
} }
return FAIL_RETURN; return FAIL_RETURN;
} }
int iotx_dm_subscribe_node(dm_mgr_dev_node_t *node)
{
int res = 0;
if (node == NULL) {
return INVALID_PARAMETER;
}
//send app to subscribe mqtt
const char subscribe_cmd[] =
"{\"cmd\":\"subscribe\",\"data\":{\"productCode\":\"%s\",\"deviceCode\":\"%s\"}}";
int len = strlen(subscribe_cmd) +strlen(node->productCode)+ strlen(node->deviceCode) + 1;
void* buf = malloc(len);
if (buf){
HAL_Snprintf(buf, len, subscribe_cmd, node->productCode,node->deviceCode);
#if 1
kk_ipc_send(IPC_MID2APP, buf, len);
free(buf);
#else
dm_queue_msg_insert4(buf);
#endif
}else{
ERROR_PRINT("\n [%d][%s] malloc faild kk_ipc_send \n", __LINE__, __FUNCTION__);
return FAIL_RETURN;
}
INFO_PRINT("\n [%d][%s] [%lu] send app to subscribe mqtt \n", __LINE__, __FUNCTION__, HAL_UptimeMs());
return SUCCESS_RETURN;
}
int iotx_dm_subscribe(_IN_ int devid) int iotx_dm_subscribe(_IN_ int devid)
{ {
......
...@@ -67,6 +67,22 @@ int dm_mgr_search_dev_by_devid(_IN_ int devid, _OU_ dm_mgr_dev_node_t **node) ...@@ -67,6 +67,22 @@ int dm_mgr_search_dev_by_devid(_IN_ int devid, _OU_ dm_mgr_dev_node_t **node)
ERROR_PRINT("Device Not Found, devid: %d", devid); ERROR_PRINT("Device Not Found, devid: %d", devid);
return FAIL_RETURN; return FAIL_RETURN;
} }
void dm_mgr_resubscribe(void)
{
dm_mgr_ctx *ctx = _dm_mgr_get_ctx();
dm_mgr_dev_node_t *search_node = NULL;
list_for_each_entry(search_node, &ctx->dev_list, linked_list, dm_mgr_dev_node_t) {
/* dm_log_debug("Device Found, devid: %d", devid); */
if (search_node) {
//printf("----------------------------------------->[%s][%d] \n",__FUNCTION__,__LINE__);
iotx_dm_subscribe_node(search_node);
}
}
return ;
}
static int _dm_mgr_search_dev_by_pkdn(_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ dm_mgr_dev_node_t **node) static int _dm_mgr_search_dev_by_pkdn(_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ dm_mgr_dev_node_t **node)
{ {
dm_mgr_ctx *ctx = _dm_mgr_get_ctx(); dm_mgr_ctx *ctx = _dm_mgr_get_ctx();
......
...@@ -31,7 +31,7 @@ void kk_sendData2app(void *info, void *payload,int isAsync){ ...@@ -31,7 +31,7 @@ void kk_sendData2app(void *info, void *payload,int isAsync){
} }
const char DM_MSG_THING_SUB_REGISTER_METHOD[] = "thing.sub.register"; const char DM_MSG_THING_SUB_REGISTER_METHOD[] = "thing.sub.register";
const char DM_MSG_THING_SUB_REGISTER_PARAMS[] = "[{\"productCode\":\"%s\",\"deviceCode\":\"%s\"}]"; const char DM_MSG_THING_SUB_REGISTER_PARAMS[] = "{\"productCode\":\"%s\",\"deviceCode\":\"%s\"}";
int dm_msg_thing_sub_register(_IN_ char productCode[DEVICE_CODE_MAXLEN], _IN_ char deviceCode[DEVICE_CODE_MAXLEN], int dm_msg_thing_sub_register(_IN_ char productCode[DEVICE_CODE_MAXLEN], _IN_ char deviceCode[DEVICE_CODE_MAXLEN],
_OU_ dm_msg_request_t *request) _OU_ dm_msg_request_t *request)
...@@ -768,29 +768,17 @@ int dm_msg_thing_syncinfo_reply(void){ ...@@ -768,29 +768,17 @@ int dm_msg_thing_syncinfo_reply(void){
dm_mgr_dev_node_t *node = NULL; dm_mgr_dev_node_t *node = NULL;
char *info = NULL; char *info = NULL;
int res = 0; int res = 0;
memset(&request, 0, sizeof(kk_msg_request_payload_t)); memset(&request, 0, sizeof(kk_msg_request_payload_t));
memset(&response, 0, sizeof(kk_msg_response_t)); memset(&response, 0, sizeof(kk_msg_response_t));
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
res = dm_mgr_search_dev_by_devid(KK_DM_DEVICE_CCU_DEVICEID, &node); res = dm_mgr_search_dev_by_devid(KK_DM_DEVICE_CCU_DEVICEID, &node);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return FAIL_RETURN; return FAIL_RETURN;
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
//res = dm_msg_request_parse((char *)payload, payload_len, &request);
//if (res < SUCCESS_RETURN) {
//ERROR_PRINT("dm_msg_request_parse failed");
//return res ;
//}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
response.msgTypeStr = KK_THING_SERVICE_SYNCINFO_REPLY; response.msgTypeStr = KK_THING_SERVICE_SYNCINFO_REPLY;
memcpy(response.productCode, node->productCode, strlen( node->productCode)); memcpy(response.productCode, node->productCode, strlen( node->productCode));
memcpy(response.deviceCode, node->deviceCode, strlen(node->deviceCode)); memcpy(response.deviceCode, node->deviceCode, strlen(node->deviceCode));
response.code = (res == SUCCESS_RETURN) ? (IOTX_DM_ERR_CODE_SUCCESS) : (IOTX_DM_ERR_CODE_REQUEST_ERROR); response.code = (res == SUCCESS_RETURN) ? (IOTX_DM_ERR_CODE_SUCCESS) : (IOTX_DM_ERR_CODE_REQUEST_ERROR);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
info = kk_sync_get_info(); info = kk_sync_get_info();
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
dm_msg_response(&request, &response, info, strlen(info), NULL); dm_msg_response(&request, &response, info, strlen(info), NULL);
free(info); free(info);
return SUCCESS_RETURN; return SUCCESS_RETURN;
...@@ -812,14 +800,11 @@ int dm_msg_thing_syncdeviceinfo_reply(cJSON *msgId){ ...@@ -812,14 +800,11 @@ int dm_msg_thing_syncdeviceinfo_reply(cJSON *msgId){
request.id.value = msgId->valuestring; request.id.value = msgId->valuestring;
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
res = dm_mgr_search_dev_by_devid(KK_DM_DEVICE_CCU_DEVICEID, &node); res = dm_mgr_search_dev_by_devid(KK_DM_DEVICE_CCU_DEVICEID, &node);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return FAIL_RETURN; return FAIL_RETURN;
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
//res = dm_msg_request_parse((char *)payload, payload_len, &request); //res = dm_msg_request_parse((char *)payload, payload_len, &request);
//if (res < SUCCESS_RETURN) { //if (res < SUCCESS_RETURN) {
//ERROR_PRINT("dm_msg_request_parse failed"); //ERROR_PRINT("dm_msg_request_parse failed");
......
...@@ -402,7 +402,6 @@ static int kk_service_addDeviceToRoom_reply(cJSON *param,cJSON *msgId) ...@@ -402,7 +402,6 @@ static int kk_service_addDeviceToRoom_reply(cJSON *param,cJSON *msgId)
if(param == NULL || msgId == NULL){ if(param == NULL || msgId == NULL){
return INVALID_PARAMETER; return INVALID_PARAMETER;
} }
INFO_PRINT(" adddevicetoroom reply \n");
cJSON *deviceCode = cJSON_GetObjectItem(param, MSG_DEVICE_CODE_STR); cJSON *deviceCode = cJSON_GetObjectItem(param, MSG_DEVICE_CODE_STR);
if(deviceCode == NULL){ if(deviceCode == NULL){
return FAIL_RETURN; return FAIL_RETURN;
...@@ -411,7 +410,6 @@ static int kk_service_addDeviceToRoom_reply(cJSON *param,cJSON *msgId) ...@@ -411,7 +410,6 @@ static int kk_service_addDeviceToRoom_reply(cJSON *param,cJSON *msgId)
if(productCode == NULL){ if(productCode == NULL){
return FAIL_RETURN; return FAIL_RETURN;
} }
INFO_PRINT(" adddevicetoroom reply \n");
cJSON *info = cJSON_CreateObject(); cJSON *info = cJSON_CreateObject();
cJSON_AddStringToObject(info, MSG_TYPE_STR, KK_THING_SERVICE_ADDDEVICETOROOM_REPLY); cJSON_AddStringToObject(info, MSG_TYPE_STR, KK_THING_SERVICE_ADDDEVICETOROOM_REPLY);
cJSON_AddStringToObject(info, MSG_DEVICE_CODE_STR, deviceCode->valuestring); cJSON_AddStringToObject(info, MSG_DEVICE_CODE_STR, deviceCode->valuestring);
...@@ -423,13 +421,10 @@ static int kk_service_addDeviceToRoom_reply(cJSON *param,cJSON *msgId) ...@@ -423,13 +421,10 @@ static int kk_service_addDeviceToRoom_reply(cJSON *param,cJSON *msgId)
cJSON_AddStringToObject(payload, "version", "1.0"); cJSON_AddStringToObject(payload, "version", "1.0");
cJSON_AddStringToObject(payload, "code", "0"); cJSON_AddStringToObject(payload, "code", "0");
cJSON_AddStringToObject(payload, "msgId", msgId->valuestring); cJSON_AddStringToObject(payload, "msgId", msgId->valuestring);
INFO_PRINT(" adddevicetoroom reply \n");
cJSON *Item = cJSON_CreateObject(); cJSON *Item = cJSON_CreateObject();
cJSON_AddItemToObject(payload, "params", Item); cJSON_AddItemToObject(payload, "params", Item);
char *payload11=cJSON_Print(payload); char *payload11=cJSON_Print(payload);
INFO_PRINT(" adddevicetoroom reply \n");
kk_sendData2app(infff,payload11,0); kk_sendData2app(infff,payload11,0);
INFO_PRINT(" adddevicetoroom reply \n");
free(payload11); free(payload11);
free(infff); free(infff);
cJSON_Delete(payload); cJSON_Delete(payload);
...@@ -1177,7 +1172,7 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) ...@@ -1177,7 +1172,7 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
iotx_dm_dev_online(KK_DM_DEVICE_CCU_DEVICEID);//first online,report the online status iotx_dm_dev_online(KK_DM_DEVICE_CCU_DEVICEID);//first online,report the online status
usleep(200000); usleep(200000);
dm_msg_ccu_property_post(node); dm_msg_ccu_property_post(node);
kk_load_subDevice(); dm_mgr_resubscribe();
} }
s_CloudStatus = atoi(state->valuestring); s_CloudStatus = atoi(state->valuestring);
}else if (strcmp(typeJson->valuestring,"/upgrade") == 0){ }else if (strcmp(typeJson->valuestring,"/upgrade") == 0){
......
...@@ -100,6 +100,7 @@ static int kk_subDev_db_Init(void) ...@@ -100,6 +100,7 @@ static int kk_subDev_db_Init(void)
_kk_subDb_unlock(); _kk_subDb_unlock();
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
/************************************************************ /************************************************************
*功能描述:开机从设备数据库导出数据到内存 *功能描述:开机从设备数据库导出数据到内存
*输入参数:无 *输入参数:无
...@@ -107,7 +108,7 @@ static int kk_subDev_db_Init(void) ...@@ -107,7 +108,7 @@ static int kk_subDev_db_Init(void)
*返 回 值:0:成功;其他:失败 *返 回 值:0:成功;其他:失败
*其他说明: *其他说明:
*************************************************************/ *************************************************************/
int kk_load_subDevice(void) static int _kk_load_subDevice(void)
{ {
const char *searchCmd = "select * from SubDeviceInfo;"; const char *searchCmd = "select * from SubDeviceInfo;";
sqlite3_stmt *stmt; sqlite3_stmt *stmt;
...@@ -134,7 +135,7 @@ int kk_load_subDevice(void) ...@@ -134,7 +135,7 @@ int kk_load_subDevice(void)
} }
usleep(100000); usleep(100000);
// send the topo info // send the topo info
iotx_dm_subscribe(devId); //iotx_dm_subscribe(devId);
//sync the data from property db //sync the data from property db
kk_property_sync_values((char*)sqlite3_column_text(stmt, DB_SUB_DEVICECODE)); kk_property_sync_values((char*)sqlite3_column_text(stmt, DB_SUB_DEVICECODE));
...@@ -177,7 +178,8 @@ int kk_subDb_init(void) ...@@ -177,7 +178,8 @@ int kk_subDb_init(void)
ERROR_PRINT("[%s][%d]kk_wlist_db_Init FAIL!!!\n",__FUNCTION__,__LINE__); ERROR_PRINT("[%s][%d]kk_wlist_db_Init FAIL!!!\n",__FUNCTION__,__LINE__);
} }
//_kk_load_subDevice(); _kk_load_subDevice();
//kk_load_subDevice();
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
/************************************************************ /************************************************************
......
...@@ -100,7 +100,7 @@ static cJSON * kk_get_room_devices(const char *roomId) ...@@ -100,7 +100,7 @@ static cJSON * kk_get_room_devices(const char *roomId)
res = dm_mgr_get_device_by_devicecode((char*)deviceCode,&node); res = dm_mgr_get_device_by_devicecode((char*)deviceCode,&node);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
ERROR_PRINT("ERROR [%s][%d] res:%d\n",__FUNCTION__,__LINE__,res); ERROR_PRINT("ERROR [%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
return devs; return NULL;
} }
if(kk_check_multi_ep_num(deviceCode)){ if(kk_check_multi_ep_num(deviceCode)){
cJSON_AddStringToObject(dev,KK_SYNC_SCENE_EPNUM_STR,epNum); cJSON_AddStringToObject(dev,KK_SYNC_SCENE_EPNUM_STR,epNum);
...@@ -284,7 +284,6 @@ static cJSON *kk_get_ccu_properties_info(cJSON *data) ...@@ -284,7 +284,6 @@ static cJSON *kk_get_ccu_properties_info(cJSON *data)
propertyStr = (char*)sqlite3_column_text(stmt, DB_IDENTIFITER); propertyStr = (char*)sqlite3_column_text(stmt, DB_IDENTIFITER);
valueType = sqlite3_column_int(stmt, DB_VALUETYPE); valueType = sqlite3_column_int(stmt, DB_VALUETYPE);
valueStr = (char*)sqlite3_column_text(stmt, DB_VALUE); valueStr = (char*)sqlite3_column_text(stmt, DB_VALUE);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if(valueType == KK_TSL_DATA_TYPE_TEXT){ if(valueType == KK_TSL_DATA_TYPE_TEXT){
if(!strcmp(propertyStr,"ArmingState")){ if(!strcmp(propertyStr,"ArmingState")){
cJSON_AddNumberToObject(property, propertyStr, atoi(valueStr)); cJSON_AddNumberToObject(property, propertyStr, atoi(valueStr));
...@@ -343,7 +342,6 @@ static cJSON *kk_get_properties_info(char *deviceCode,int devType) ...@@ -343,7 +342,6 @@ static cJSON *kk_get_properties_info(char *deviceCode,int devType)
int num = 0; int num = 0;
split(propertyStr,"_",propertiesbuf,&num); split(propertyStr,"_",propertiesbuf,&num);
if(num==2){ if(num==2){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON_AddStringToObject(propertyItem, "epNum",propertiesbuf[1]); cJSON_AddStringToObject(propertyItem, "epNum",propertiesbuf[1]);
if(valueType == KK_TSL_DATA_TYPE_TEXT){ if(valueType == KK_TSL_DATA_TYPE_TEXT){
cJSON_AddStringToObject(propertyItem, propertiesbuf[0], valueStr); cJSON_AddStringToObject(propertyItem, propertiesbuf[0], valueStr);
...@@ -355,7 +353,6 @@ static cJSON *kk_get_properties_info(char *deviceCode,int devType) ...@@ -355,7 +353,6 @@ static cJSON *kk_get_properties_info(char *deviceCode,int devType)
cJSON_AddNumberToObject(propertyItem, propertiesbuf[0], atof(valueStr)); cJSON_AddNumberToObject(propertyItem, propertiesbuf[0], atof(valueStr));
} }
}else{ }else{
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON_AddStringToObject(propertyItem, "epNum","1"); cJSON_AddStringToObject(propertyItem, "epNum","1");
if(valueType == KK_TSL_DATA_TYPE_TEXT){ if(valueType == KK_TSL_DATA_TYPE_TEXT){
cJSON_AddStringToObject(propertyItem, propertyStr, valueStr); cJSON_AddStringToObject(propertyItem, propertyStr, valueStr);
...@@ -368,9 +365,7 @@ static cJSON *kk_get_properties_info(char *deviceCode,int devType) ...@@ -368,9 +365,7 @@ static cJSON *kk_get_properties_info(char *deviceCode,int devType)
} }
} }
cJSON_AddItemToArray(eps,propertyItem); cJSON_AddItemToArray(eps,propertyItem);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON_AddItemToObject(obj, "eps", eps); cJSON_AddItemToObject(obj, "eps", eps);
sqlite3_free(sqlCmd); sqlite3_free(sqlCmd);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
...@@ -395,21 +390,15 @@ static cJSON *kk_get_indoor_properties_info(char *deviceCode) ...@@ -395,21 +390,15 @@ static cJSON *kk_get_indoor_properties_info(char *deviceCode)
cJSON *obj = cJSON_CreateObject(); cJSON *obj = cJSON_CreateObject();
cJSON *eps = cJSON_CreateArray(); cJSON *eps = cJSON_CreateArray();
count = kk_indoorAir_query_epnums(deviceCode,eplist); count = kk_indoorAir_query_epnums(deviceCode,eplist);
printf("-------------->count:%d\n",count);
for(i = 0; i < count; i++){ for(i = 0; i < count; i++){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
sqlCmd = sqlite3_mprintf("select * from indoorAirProperties WHERE deviceCode = '%s' and epNum=%d;",deviceCode,eplist[i]); sqlCmd = sqlite3_mprintf("select * from indoorAirProperties WHERE deviceCode = '%s' and epNum=%d;",deviceCode,eplist[i]);
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL); sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
cJSON *propertyItem = cJSON_CreateObject(); cJSON *propertyItem = cJSON_CreateObject();
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON_AddNumberToObject(propertyItem, "epNum",eplist[i]); cJSON_AddNumberToObject(propertyItem, "epNum",eplist[i]);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
while(sqlite3_step(stmt) == SQLITE_ROW){ while(sqlite3_step(stmt) == SQLITE_ROW){
propertyStr = (char*)sqlite3_column_text(stmt, DB_INDOORAIR_IDENTIFITER); propertyStr = (char*)sqlite3_column_text(stmt, DB_INDOORAIR_IDENTIFITER);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
valueType = sqlite3_column_int(stmt, DB_INDOORAIR_VALUETYPE); valueType = sqlite3_column_int(stmt, DB_INDOORAIR_VALUETYPE);
valueStr = (char*)sqlite3_column_text(stmt, DB_INDOORAIR_VALUE); valueStr = (char*)sqlite3_column_text(stmt, DB_INDOORAIR_VALUE);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if(valueType == KK_TSL_DATA_TYPE_TEXT){ if(valueType == KK_TSL_DATA_TYPE_TEXT){
cJSON_AddStringToObject(propertyItem, propertyStr, valueStr); cJSON_AddStringToObject(propertyItem, propertyStr, valueStr);
}else if(valueType == KK_TSL_DATA_TYPE_INT|| }else if(valueType == KK_TSL_DATA_TYPE_INT||
...@@ -419,11 +408,9 @@ static cJSON *kk_get_indoor_properties_info(char *deviceCode) ...@@ -419,11 +408,9 @@ static cJSON *kk_get_indoor_properties_info(char *deviceCode)
}else if(valueType == KK_TSL_DATA_TYPE_DOUBLE){ }else if(valueType == KK_TSL_DATA_TYPE_DOUBLE){
cJSON_AddNumberToObject(propertyItem, propertyStr, atof(valueStr)); cJSON_AddNumberToObject(propertyItem, propertyStr, atof(valueStr));
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
} }
cJSON_AddItemToArray(eps,propertyItem); cJSON_AddItemToArray(eps,propertyItem);
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON_AddItemToObject(obj, "eps", eps); cJSON_AddItemToObject(obj, "eps", eps);
cJSON_AddNumberToObject(obj, "EpTotal", count); cJSON_AddNumberToObject(obj, "EpTotal", count);
cJSON_AddNumberToObject(obj, "CombineDeviceFlag", 1); cJSON_AddNumberToObject(obj, "CombineDeviceFlag", 1);
...@@ -453,7 +440,6 @@ static int kk_get_properties_info_obj(char *deviceCode) ...@@ -453,7 +440,6 @@ static int kk_get_properties_info_obj(char *deviceCode)
propertyStr = (char*)sqlite3_column_text(stmt, DB_IDENTIFITER); propertyStr = (char*)sqlite3_column_text(stmt, DB_IDENTIFITER);
valueType = sqlite3_column_int(stmt, DB_VALUETYPE); valueType = sqlite3_column_int(stmt, DB_VALUETYPE);
valueStr = (char*)sqlite3_column_text(stmt, DB_VALUE); valueStr = (char*)sqlite3_column_text(stmt, DB_VALUE);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if(valueType == KK_TSL_DATA_TYPE_TEXT){ if(valueType == KK_TSL_DATA_TYPE_TEXT){
cJSON_AddStringToObject(obj, propertyStr, valueStr); cJSON_AddStringToObject(obj, propertyStr, valueStr);
}else if(valueType == KK_TSL_DATA_TYPE_INT|| }else if(valueType == KK_TSL_DATA_TYPE_INT||
...@@ -623,13 +609,8 @@ static int kk_get_gw_devices_info(cJSON *gwdevices) ...@@ -623,13 +609,8 @@ static int kk_get_gw_devices_info(cJSON *gwdevices)
cJSON_AddStringToObject(gwdevicesItem, KK_SYNC_PRODUCTCODE_STR, gw_productCode); cJSON_AddStringToObject(gwdevicesItem, KK_SYNC_PRODUCTCODE_STR, gw_productCode);
cJSON_AddStringToObject(gwdevicesItem, KK_SYNC_SN_STR, ""); cJSON_AddStringToObject(gwdevicesItem, KK_SYNC_SN_STR, "");
cJSON_AddNumberToObject(gwdevicesItem, KK_SYNC_STATUS_STR, 1); cJSON_AddNumberToObject(gwdevicesItem, KK_SYNC_STATUS_STR, 1);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_get_gw_properties_info(gwdevicesItem); kk_get_gw_properties_info(gwdevicesItem);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_get_sub_devices_info(gwdevicesItem,gw_deviceCode); kk_get_sub_devices_info(gwdevicesItem,gw_deviceCode);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON_AddItemToArray(gwdevices, gwdevicesItem); cJSON_AddItemToArray(gwdevices, gwdevicesItem);
} }
sqlite3_free(sqlCmd); sqlite3_free(sqlCmd);
...@@ -1123,27 +1104,19 @@ char *kk_sync_get_info() ...@@ -1123,27 +1104,19 @@ char *kk_sync_get_info()
cJSON *data = cJSON_CreateObject(); cJSON *data = cJSON_CreateObject();
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_get_rooms_info(data); kk_get_rooms_info(data);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_get_devices_info(data); kk_get_devices_info(data);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_get_scenes_info(data); kk_get_scenes_info(data);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
//HAL_GetDevice_Code(ccu_deviceCode); //HAL_GetDevice_Code(ccu_deviceCode);
HAL_Get_ccuid(ccu_deviceCode); HAL_Get_ccuid(ccu_deviceCode);
HAL_GetProduct_Code(ccu_productCode); HAL_GetProduct_Code(ccu_productCode);
HAL_GetVersion(version); HAL_GetVersion(version);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON_AddStringToObject(data, KK_SYNC_DEVICECODE_STR,ccu_deviceCode); cJSON_AddStringToObject(data, KK_SYNC_DEVICECODE_STR,ccu_deviceCode);
cJSON_AddStringToObject(data, KK_SYNC_NANE_STR, "newccu"); cJSON_AddStringToObject(data, KK_SYNC_NANE_STR, "newccu");
sprintf(cloudstatus_str, "%d", kk_get_cloudstatus()); sprintf(cloudstatus_str, "%d", kk_get_cloudstatus());
cJSON_AddStringToObject(data, KK_SYNC_ONLINE_STR, cloudstatus_str); cJSON_AddStringToObject(data, KK_SYNC_ONLINE_STR, cloudstatus_str);
cJSON_AddStringToObject(data, KK_SYNC_PRODUCTCODE_STR, ccu_productCode); cJSON_AddStringToObject(data, KK_SYNC_PRODUCTCODE_STR, ccu_productCode);
cJSON_AddStringToObject(data, KK_SYNC_VERSION_STR, version); cJSON_AddStringToObject(data, KK_SYNC_VERSION_STR, version);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_get_ccu_properties_info(data); kk_get_ccu_properties_info(data);
......
...@@ -544,6 +544,7 @@ static int kk_alarm_notify_handle(dm_mgr_dev_node_t *node,char *identifier,char ...@@ -544,6 +544,7 @@ static int kk_alarm_notify_handle(dm_mgr_dev_node_t *node,char *identifier,char
int currentValue = 0; int currentValue = 0;
char armingstate[16] = {0}; char armingstate[16] = {0};
int ret = 0; int ret = 0;
int needSave = 0;
if(node == NULL || identifier == NULL){ if(node == NULL || identifier == NULL){
return -1; return -1;
} }
...@@ -570,13 +571,20 @@ static int kk_alarm_notify_handle(dm_mgr_dev_node_t *node,char *identifier,char ...@@ -570,13 +571,20 @@ static int kk_alarm_notify_handle(dm_mgr_dev_node_t *node,char *identifier,char
cJSON *param = cJSON_CreateObject(); cJSON *param = cJSON_CreateObject();
if(strcmp(identifier,"BatteryAlarm") == 0){ if(strcmp(identifier,"BatteryAlarm") == 0){
cJSON_AddStringToObject(param, "LowBatteryState", "1"); cJSON_AddStringToObject(param, "LowBatteryState", "1");
needSave = 1;
}else if(strcmp(identifier,"DismantleState") == 0 && atoi(valueBuf) == 1){ }else if(strcmp(identifier,"DismantleState") == 0 && atoi(valueBuf) == 1){
cJSON_AddStringToObject(param, "DismantleState", "1"); cJSON_AddStringToObject(param, "DismantleState", "1");
needSave = 1;
}else if(strcmp(identifier,"SmokeSensorState") == 0 && atoi(valueBuf) == 1){ }else if(strcmp(identifier,"SmokeSensorState") == 0 && atoi(valueBuf) == 1){
cJSON_AddStringToObject(param, "CommonAlarmState", "1"); cJSON_AddStringToObject(param, "CommonAlarmState", "1");
needSave = 1;
}else if(strcmp(identifier,"DismantleState") == 0 && atoi(valueBuf) == 0){
}
else if(strcmp(identifier,"SmokeSensorState") == 0 && atoi(valueBuf) == 0){
} }
else{ else{
cJSON_AddStringToObject(param, "CommonAlarmState", "1"); cJSON_AddStringToObject(param, "CommonAlarmState", "1");
needSave = 1;
} }
cJSON_AddItemToObject(payload, "params", param); cJSON_AddItemToObject(payload, "params", param);
char *payload11=cJSON_Print(payload); char *payload11=cJSON_Print(payload);
...@@ -584,16 +592,19 @@ static int kk_alarm_notify_handle(dm_mgr_dev_node_t *node,char *identifier,char ...@@ -584,16 +592,19 @@ static int kk_alarm_notify_handle(dm_mgr_dev_node_t *node,char *identifier,char
if(currentValue == 2)//24小时警戒 if(currentValue == 2)//24小时警戒
{ {
kk_sendData2app(infff,payload11,0); kk_sendData2app(infff,payload11,0);
if(needSave == 1)
kk_history_insert_sensor_info(node->deviceCode,identifier,valueBuf,HAL_GetTime()); kk_history_insert_sensor_info(node->deviceCode,identifier,valueBuf,HAL_GetTime());
} }
else if(currentValue == 1 && atoi(armingstate) == 0) //离家布防 else if(currentValue == 1 && atoi(armingstate) == 0) //离家布防
{ {
kk_sendData2app(infff,payload11,0); kk_sendData2app(infff,payload11,0);
if(needSave == 1)
kk_history_insert_sensor_info(node->deviceCode,identifier,valueBuf,HAL_GetTime()); kk_history_insert_sensor_info(node->deviceCode,identifier,valueBuf,HAL_GetTime());
} }
else if(currentValue == 0 && atoi(armingstate) == 2) //在家布防 else if(currentValue == 0 && atoi(armingstate) == 2) //在家布防
{ {
kk_sendData2app(infff,payload11,0); kk_sendData2app(infff,payload11,0);
if(needSave == 1)
kk_history_insert_sensor_info(node->deviceCode,identifier,valueBuf,HAL_GetTime()); kk_history_insert_sensor_info(node->deviceCode,identifier,valueBuf,HAL_GetTime());
} }
else if(atoi(armingstate) == 3 && currentValue == 0 ) else if(atoi(armingstate) == 3 && currentValue == 0 )
...@@ -606,10 +617,12 @@ static int kk_alarm_notify_handle(dm_mgr_dev_node_t *node,char *identifier,char ...@@ -606,10 +617,12 @@ static int kk_alarm_notify_handle(dm_mgr_dev_node_t *node,char *identifier,char
INFO_PRINT("state: [%d] \n",state); INFO_PRINT("state: [%d] \n",state);
if(state){ if(state){
kk_sendData2app(infff,payload11,0); kk_sendData2app(infff,payload11,0);
if(needSave == 1)
kk_history_insert_sensor_info(node->deviceCode,identifier,valueBuf,HAL_GetTime()); kk_history_insert_sensor_info(node->deviceCode,identifier,valueBuf,HAL_GetTime());
} }
} }
} }
needSave = 0;
free(payload11); free(payload11);
free(infff); free(infff);
cJSON_Delete(payload); cJSON_Delete(payload);
...@@ -887,7 +900,6 @@ void kk_platMsg_handle(void* data, char* chalMark){ ...@@ -887,7 +900,6 @@ void kk_platMsg_handle(void* data, char* chalMark){
for(index = 0; index < eventItem->output_data_number;index++){ for(index = 0; index < eventItem->output_data_number;index++){
itemStr = cJSON_GetObjectItem(jsonPay, eventItem->identifier); itemStr = cJSON_GetObjectItem(jsonPay, eventItem->identifier);
itemData = eventItem->output_datas + index; itemData = eventItem->output_datas + index;
printf("------------111--------->itemData->identifier:%s\n",itemData->identifier);
cJSON * itemDataIdentifier = cJSON_GetObjectItem(jsonPay, itemData->identifier); cJSON * itemDataIdentifier = cJSON_GetObjectItem(jsonPay, itemData->identifier);
if(itemDataIdentifier != NULL){ if(itemDataIdentifier != NULL){
memset(tmpStr,0x0,sizeof(tmpStr)); memset(tmpStr,0x0,sizeof(tmpStr));
......
...@@ -1699,11 +1699,11 @@ ...@@ -1699,11 +1699,11 @@
"name": "HD HVAC Floor Heating All in one", "name": "HD HVAC Floor Heating All in one",
"type": "ZR", "type": "ZR",
"ota": true, "ota": true,
"b_pid": 3090, "b_pid": 3097,
"eps": [ "eps": [
{ {
"ep": "1", "ep": "1:2:3",
"zid": "0300", "zid": "0300",
"zname": "Heating Cooling Unit", "zname": "Heating Cooling Unit",
"b_oid": 0, "b_oid": 0,
...@@ -1712,27 +1712,58 @@ ...@@ -1712,27 +1712,58 @@
"client": "0003:0006", "client": "0003:0006",
"server": "0000:0003:0004:0005:0006:0201:0202" "server": "0000:0003:0004:0005:0006:0201:0202"
} }
}
]
}, },
{ {
"ep": "2", "pid": "01018631",
"zid": "0300", "name": "HD Dimmable Light Panel 1G",
"zname": "Heating Cooling Unit", "type": "ZR",
"ota": true,
"b_pid": 3091,
"eps": [
{
"ep": "1",
"zid": "0101",
"zname": "Dimmable Light",
"b_oid": 0, "b_oid": 0,
"cluster": { "cluster": {
"client": "0003:0006", "client": "0003:0019",
"server": "0000:0003:0004:0005:0006:0201" "server": "0000:0003:0004:0005:0006:0008:0B05"
} }
}, },
{ {
"ep": "3", "ep": "21",
"zid": "0300", "zid": "0003",
"zname": "Heating Cooling Unit", "zname": "Level Controllable Output",
"b_oid": 0, "b_oid": 0,
"cluster": { "cluster": {
"client": "0003:0006", "client": "0003:0019",
"server": "0000:0003:0004:0005:0006:0201:0202" "server": "0000:0003:0004:0005:0008:0B05"
}
}
]
},
{
"pid": "01018630",
"name": "HD SCR Dimmable Light Panel",
"type": "ZR",
"ota": true,
"b_pid": 3102,
"eps": [
{
"ep": "1",
"zid": "0101",
"zname": "Dimmable Light",
"b_oid": 0,
"cluster": {
"client": "0003:0019",
"server": "0000:0003:0004:0005:0006:0008:0B05"
} }
} }
] ]
......
#!/bin/sh #!/bin/sh
if [ ! -f "/sbin/jq" ]
then
cp /app/ccuApps/jq /sbin
fi
if [ -f "/app/nx5Apps/syscfg.json" ]
then
if [ ! -f "/data/syscfg.json" ]
then
cp /app/nx5Apps/syscfg.json /data
fi
embbedflag=`cat /data/syscfg.json|jq ."ccuembbed"`
#embbedflag="0"
echo $embbedflag
if [ "$embbedflag" = '"0"' ]
then
echo "do not start the ccu process"
exit 0
fi
fi
nanomsg_File="/app/ccuApps/lib/libnanomsg.so.5" nanomsg_File="/app/ccuApps/lib/libnanomsg.so.5"
ev_File="/app/ccuApps/lib/libev.so.4" ev_File="/app/ccuApps/lib/libev.so.4"
sqlite_File="/app/ccuApps/lib/libsqlite3.so.0" sqlite_File="/app/ccuApps/lib/libsqlite3.so.0"
...@@ -44,7 +64,7 @@ sleep 3 ...@@ -44,7 +64,7 @@ sleep 3
/app/ccuApps/bin/kk_cloud & /app/ccuApps/bin/kk_cloud &
sleep 1 sleep 1
#/home/kk/process_check.sh >/dev/null 2>&1 & #/home/kk/process_check.sh >/dev/null 2>&1 &
/app/ccuApps/bin/smarthome_z3gw_nx5 -r1 -l3 --device-def=/app/ccuApps/kk_device_def.json --db=/data/kk/kk_z3gw.db --uart=/dev/ttyS1& /app/ccuApps/bin/smarthome_z3gw_nx5 -r0 -l3 --device-def=/app/ccuApps/kk_device_def.json --db=/data/kk/kk_z3gw.db --uart=/dev/ttyS1&
sleep 2 sleep 2
/app/ccuApps/bin/kk_lan & /app/ccuApps/bin/kk_lan &
sleep 1 sleep 1
......
...@@ -24,7 +24,7 @@ if [ "$PIDS" != "" ]; then ...@@ -24,7 +24,7 @@ if [ "$PIDS" != "" ]; then
else else
echo "smarthome_z3gw_nx5 is not running ,now restart smarthome_z3gw_nx5" echo "smarthome_z3gw_nx5 is not running ,now restart smarthome_z3gw_nx5"
export LD_LIBRARY_PATH=/app/ccuApps/lib export LD_LIBRARY_PATH=/app/ccuApps/lib
/app/ccuApps/bin/smarthome_z3gw_nx5 -r1 -l3 --device-def=/app/ccuApps/kk_device_def.json --db=/data/kk/kk_z3gw.db --uart=/dev/ttyS1& /app/ccuApps/bin/smarthome_z3gw_nx5 -r0 -l3 --device-def=/app/ccuApps/kk_device_def.json --db=/data/kk/kk_z3gw.db --uart=/dev/ttyS1&
fi fi
sleep 1 sleep 1
PIDS=`ps|grep kk_lan |grep -v grep | awk '{print $1}'` PIDS=`ps|grep kk_lan |grep -v grep | awk '{print $1}'`
......
File added
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