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

【20210826】

parent 8325f75c
......@@ -395,7 +395,9 @@ static int kk_parse_syncinfo(cJSON *payload)
cJSON * newccuItem;
cJSON *valuejson;
int value;
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_map_dev_deinit();
......@@ -426,9 +428,13 @@ static int kk_parse_syncinfo(cJSON *payload)
properties = cJSON_GetObjectItem(subitem,MSG_PROPERTIES_STR);
kk_map_dev_node_add(deviceCode,productCode,gwdevicecode,(onlineStatus->valueint==1)?"1":"0");
kk_lan_property_post_deal(deviceCode,properties);
//property_syn_deal(deviceCode,properties);
kk_lan_property_syn_deal(deviceCode,properties);
subitem = subitem->next;
}
}
......
......@@ -27,7 +27,7 @@ static int kk_findccu_ack(int sockfd,struct sockaddr_in *addr){
return -1;
}
char ccuid[32] = {0};
kk_lan_get_ccuid(ccuid);
kk_lan_get_ccuid(ccuid);
json=cJSON_CreateObject();
if(json){
args = cJSON_CreateObject();
......@@ -81,9 +81,9 @@ void *kk_findccu_handle(void *data)
saddr.sin_port = htons(FINDCCU_LOCAL_PORT);
if(bind(sockfd, (struct sockaddr*)&saddr, sizeof(saddr)) == -1)
{
{
ERROR_PRINT("bind error...\n");
}
}
while (1)
{
r = recvfrom(sockfd, recvline, sizeof(recvline), 0 , (struct sockaddr*)&presaddr, &len);
......
......@@ -60,7 +60,7 @@ static void kk_lan_ccuid_init(void)
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));
_setDevice_Code(KK_CCU_ID,strlen(KK_CCU_ID));
}
}
......
#include "kk_data_mng.h"
#include "kk_lan_vp_ctrl.h"
#include "kk_lan_debug.h"
#include "cJSON.h"
cJSON *PowerSwitch_msg_build(int ep,int onoff)
......
......@@ -20,7 +20,7 @@
typedef struct {
int socketfd;
char ip[18];
char ip[18];
} kk_clientInfo_t;
static kk_clientInfo_t s_ConnInfo[LISTEN_MAX] = {0};
static pthread_mutex_t data_mutex;
......@@ -48,8 +48,8 @@ int kk_send_data_to_sdk(char *buf)
return 0;
}
static int _kk_handle_data(char *buf,int sockfd){
char *pStart = NULL,*pEnd = NULL;
char tmpBuf[BUF_SIZE] = {0};
char *pStart = NULL,*pEnd = NULL;
char tmpBuf[BUF_SIZE] = {0};
cJSON *json;
if(buf == NULL){
return -1;
......@@ -66,13 +66,12 @@ static int _kk_handle_data(char *buf,int sockfd){
}else{
kk_data_handle(json,sockfd);
cJSON_Delete(json);
}
}
static void PrintMesg(int i , char buf[])
{
printf("fd : %d, msg: %s\n", i , buf);
printf("fd : %d, msg: %s\n", i , buf);
}
static int kk_check_is_connect(char *ip){
......@@ -140,10 +139,10 @@ void *TCPServer()
{
//index = -1;
max_fd = client_fd > Listenfd?client_fd:Listenfd;
time_out.tv_sec = 1;//select会更改timeout的值,所以需要重新初始化超时时间
time_out.tv_usec = 0;
time_out.tv_sec = 1;//select会更改timeout的值,所以需要重新初始化超时时间
time_out.tv_usec = 0;
FD_ZERO(&server_fd_set);
FD_SET(Listenfd,&server_fd_set);
FD_SET(Listenfd,&server_fd_set);
for(i=0;i<LISTEN_MAX;i++)
{
if(s_ConnInfo[i].socketfd>0)
......
......@@ -85,13 +85,20 @@ int send_msg_to_module(cJSON *root)
cJSON * val_conver_new2old(cJSON *newccuItem,cJSON *oldccuItem,int syn_type)
{
cJSON *n_dataType = cJSON_GetObjectItem(newccuItem,DATATYPE_STRING);
cJSON * n_value = cJSON_GetObjectItem(newccuItem,"value");
cJSON *n_value = NULL,*n_dataType = NULL,*o_dataType = NULL;
cJSON *o_valueRange = NULL,*n_valueRange = NULL;
cJSON *o_dataType;
if(newccuItem==NULL||newccuItem->type!=cJSON_Object||
oldccuItem==NULL||oldccuItem->type!=cJSON_Object){
debug_log(LOG_DEBUG,"[err] para.\n");
return NULL;
}
cJSON *o_valueRange = cJSON_GetObjectItem(oldccuItem,"valueRange");
cJSON *n_valueRange = cJSON_GetObjectItem(newccuItem,"valueRange");
o_valueRange = cJSON_GetObjectItem(oldccuItem,"valueRange");
n_valueRange = cJSON_GetObjectItem(newccuItem,"valueRange");
n_dataType = cJSON_GetObjectItem(newccuItem,DATATYPE_STRING);
n_value = cJSON_GetObjectItem(newccuItem,"value");
if(syn_type==1){
o_dataType = cJSON_GetObjectItem(oldccuItem,"synType");
......@@ -101,101 +108,6 @@ cJSON * val_conver_new2old(cJSON *newccuItem,cJSON *oldccuItem,int syn_type)
return ccu_value_convert(n_dataType,n_valueRange,o_dataType,o_valueRange,n_value);
}
cJSON *kk_devicestatus_build(kk_map_dev_node_t *node)
{
int i,num = 0;
char nodeid[32] = {0};
cJSON *newccu,*oldccu;
cJSON *dev_status;
if (node == NULL ||node->syn_opcode==NULL){
return NULL;
}
newccu = node->newccu;
oldccu = node->oldccu;
if(newccu==NULL||newccu->type!=cJSON_Object ||
oldccu==NULL||oldccu->type!=cJSON_Object){
return NULL;
}
dev_status = cJSON_CreateObject();
num = cJSON_GetArraySize(newccu);
for(i=0;i<num;i++){
cJSON * newccuItem = cJSON_GetArrayItem(newccu,i);
cJSON * oldccuItem = cJSON_GetArrayItem(oldccu,i);
cJSON *synType = cJSON_GetObjectItem(oldccuItem,"synType");
cJSON *synKey = cJSON_GetObjectItem(oldccuItem,"syn");
cJSON *val = NULL;
cJSON *status = NULL;
char indexId[4] = {0};
if(synType){
if(synType->type!=cJSON_String ||synKey==NULL ||synKey->type!=cJSON_String) {
continue ;
}
status = cJSON_CreateObject();
kk_creater_nodeid(node->deviceCode,1,nodeid,atoi(node->opearteType));
cJSON_AddStringToObject(status, OPCODE_STRING, node->syn_opcode);
cJSON_AddNumberToObject(status, NODEID_STRING, atoi(nodeid));
memset(indexId,0,sizeof(indexId));
snprintf(indexId,sizeof(indexId),"%d",i+1);
cJSON_AddStringToObject(status, "index", indexId);
//todo:
if(strcmp(synType->valuestring,"timing_shutdown")==0) {
cJSON *syn_obj = cJSON_CreateObject();
double t=cJSON_GetObjectItem(newccuItem,"value")->valuedouble;
char buff[32]={0};
snprintf(buff,32,"%f",t);
if(t>0){
cJSON_AddBoolToObject(syn_obj, "enable",1);
cJSON_AddStringToObject(syn_obj, "time",buff);
}else{
cJSON_AddBoolToObject(syn_obj, "enable",0);
cJSON_AddNullToObject(syn_obj, "time");
}
cJSON_AddItemToObject(dev_status, synKey->valuestring,syn_obj);
}else{
if((val = val_conver_new2old(newccuItem,oldccuItem,1))!=NULL){
kk_lan_add_val_to_obj(dev_status,val,synKey->valuestring);
}
}
}
}
return dev_status;
}
//更新设备状态
static int _kk_lan_update_device_status(int nodeId,cJSON *opcode,cJSON *arg)
{
......
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