Commit 8fcfbe3a authored by 陈伟灿's avatar 陈伟灿

Merge branch 'yjq' into 'master'

20210713:问题

See merge request chenweican/k-sdk!88
parents 3533b5b2 8fd421e1
...@@ -8,8 +8,11 @@ CFLAGS += -I$(TOP_DIR)/common/api ...@@ -8,8 +8,11 @@ CFLAGS += -I$(TOP_DIR)/common/api
CFLAGS += -I$(TOP_DIR)/common/json CFLAGS += -I$(TOP_DIR)/common/json
CFLAGS += -I$(TOP_DIR)/common/nanomsg/include CFLAGS += -I$(TOP_DIR)/common/nanomsg/include
CFLAGS += -I$(TOP_DIR)/common/ev/include CFLAGS += -I$(TOP_DIR)/common/ev/include
CFLAGS += -I$(TOP_DIR)/common/sqlite
LDFLAGS += -lkk_tsl LDFLAGS += -lkk_tsl
LDFLAGS += -lapi_com LDFLAGS += -lapi_com
LDFLAGS += -lsqlite -ldl
ifeq ($(CONFIG_MODEL),x86) ifeq ($(CONFIG_MODEL),x86)
LDFLAGS += -L$(TOP_DIR)/common/nanomsg -lnanomsg_ubuntu LDFLAGS += -L$(TOP_DIR)/common/nanomsg -lnanomsg_ubuntu
LDFLAGS += -L$(TOP_DIR)/common/ev -lev_ubuntu LDFLAGS += -L$(TOP_DIR)/common/ev -lev_ubuntu
......
...@@ -15,60 +15,62 @@ ...@@ -15,60 +15,62 @@
#include "kk_opcode.h" #include "kk_opcode.h"
#include "com_api.h" #include "com_api.h"
#include "kk_data_mng.h" #include "kk_data_mng.h"
#include "kk_lan_ctrl.h"
const char DM_MSG_TO_MIDDWARE[] = "{\"msgtype\":\"%s\",\"productCode\":\"%s\",\"deviceCode\":\"%s\"}"; const char DM_MSG_TO_MIDDWARE[] = "{\"msgtype\":\"%s\",\"productCode\":\"%s\",\"deviceCode\":\"%s\"}";
char *strrpl(char *in, char *out, int outlen, char *src, char *dst) char *strrpl(char *in, char *out, int outlen, char *src, char *dst)
{ {
char *p = in; char *p = in;
unsigned int len = outlen - 1; unsigned int len = outlen - 1;
// 这几段检查参数合法性 // 这几段检查参数合法性
if((NULL == src) || (NULL == dst) || (NULL == in) || (NULL == out)) if((NULL == src) || (NULL == dst) || (NULL == in) || (NULL == out))
{ {
return NULL; return NULL;
} }
if((strcmp(in, "") == 0) || (strcmp(src, "") == 0)) if((strcmp(in, "") == 0) || (strcmp(src, "") == 0))
{ {
return NULL; return NULL;
} }
if(outlen <= 0) if(outlen <= 0)
{ {
return NULL; return NULL;
} }
while((*p != '\0') && (len > 0)) while((*p != '\0') && (len > 0))
{ {
if(strncmp(p, src, strlen(src)) != 0) if(strncmp(p, src, strlen(src)) != 0)
{ {
int n = strlen(out); int n = strlen(out);
out[n] = *p; out[n] = *p;
out[n + 1] = '\0'; out[n + 1] = '\0';
p++; p++;
len--; len--;
} }
else else
{ {
strcat(out, dst); strcat(out, dst);
p += strlen(src); p += strlen(src);
len -= strlen(dst); len -= strlen(dst);
} }
} }
return out; return out;
} }
static char * _kk_data_create(char *msgtype,const char *productCode,const char *deviceCode,const char *param) static char * _kk_data_create(char *msgtype,const char *productCode,const char *deviceCode,const char *param)
{ {
cJSON *root; cJSON *root;
cJSON *payload; cJSON *payload;
cJSON* infoObj; cJSON* infoObj;
char *out; char *out;
char *infoStr = NULL; char *infoStr = NULL;
int infoStr_len = 0; int infoStr_len = 0;
int res = 0; int res = 0;
char method[128] = {0}; char method[128] = {0};
strrpl(msgtype+1,method,sizeof(method),"/","."); strrpl(msgtype+1,method,sizeof(method),"/",".");
printf("method:%s\n",method); printf("method:%s\n",method);
infoStr_len = strlen(DM_MSG_TO_MIDDWARE)+strlen(productCode)+strlen(deviceCode)+strlen(msgtype)+10; infoStr_len = strlen(DM_MSG_TO_MIDDWARE)+strlen(productCode)+strlen(deviceCode)+strlen(msgtype)+10;
infoStr = malloc(infoStr_len); infoStr = malloc(infoStr_len);
if(infoStr == NULL){ if(infoStr == NULL){
...@@ -79,17 +81,17 @@ static char * _kk_data_create(char *msgtype,const char *productCode,const char * ...@@ -79,17 +81,17 @@ static char * _kk_data_create(char *msgtype,const char *productCode,const char *
snprintf(infoStr,infoStr_len,DM_MSG_TO_MIDDWARE,msgtype,productCode,deviceCode); snprintf(infoStr,infoStr_len,DM_MSG_TO_MIDDWARE,msgtype,productCode,deviceCode);
root=cJSON_CreateObject(); root=cJSON_CreateObject();
infoObj = cJSON_Parse(infoStr); infoObj = cJSON_Parse(infoStr);
cJSON_AddItemToObject(root, MSG_INFO_STR, infoObj); cJSON_AddItemToObject(root, MSG_INFO_STR, infoObj);
payload = cJSON_CreateObject(); payload = cJSON_CreateObject();
if(payload){ if(payload){
cJSON_AddItemToObject(root, MSG_PAYLOAD_STR, payload); cJSON_AddItemToObject(root, MSG_PAYLOAD_STR, payload);
cJSON_AddStringToObject(payload, "msgId", "*"); cJSON_AddStringToObject(payload, "msgId", "*");
cJSON_AddStringToObject(payload, "version", "1.0"); cJSON_AddStringToObject(payload, "version", "1.0");
cJSON_AddStringToObject(payload, "method", method); cJSON_AddStringToObject(payload, "method", method);
cJSON_AddStringToObject(payload, "params", param); cJSON_AddStringToObject(payload, "params", param);
} }
out=cJSON_Print(root); out=cJSON_Print(root);
cJSON_Minify(out); cJSON_Minify(out);
cJSON_Delete(root); cJSON_Delete(root);
...@@ -99,319 +101,506 @@ static char * _kk_data_create(char *msgtype,const char *productCode,const char * ...@@ -99,319 +101,506 @@ static char * _kk_data_create(char *msgtype,const char *productCode,const char *
return out; return out;
//free(out); /* Print to text, Delete the cJSON, print it, release the string. */ //free(out); /* Print to text, Delete the cJSON, print it, release the string. */
} }
static void kk_handle_sync_info(void) void kk_handle_sync_info(void)
{ {
char *send_data = NULL; char *send_data = NULL;
send_data = _kk_data_create(SYNC_MSG_TYPE,"*","*","*"); send_data = _kk_data_create(SYNC_MSG_TYPE,"*","*","*");
if(send_data == NULL){ if(send_data == NULL){
return; return;
} }
printf("kk_ipc_send........%s \n",send_data);
kk_ipc_send(IPC_APP2MID, send_data, strlen(send_data)+1); kk_ipc_send(IPC_APP2MID, send_data, strlen(send_data)+1);
free(send_data); free(send_data);
} }
static int kk_send_ack(cJSON *root,int sockfd) static int kk_send_ack(cJSON *root,int sockfd)
{ {
char *out = NULL; char *out = NULL;
char *tmpBuf = NULL; char *tmpBuf = NULL;
out=cJSON_Print(root); out=cJSON_Print(root);
cJSON_Minify((char*)out); cJSON_Minify((char*)out);
tmpBuf = calloc(strlen(out) + 4,1); tmpBuf = calloc(strlen(out) + 4,1);
if(tmpBuf == NULL){ if(tmpBuf == NULL){
cJSON_Delete(root); free(out);
free(out); return -1;
return -1; }
} strcat(tmpBuf,"!");
strcat(tmpBuf,"!"); strcat(tmpBuf,out);
strcat(tmpBuf,out); strcat(tmpBuf,"$");
strcat(tmpBuf,"$"); printf("tmpBuf:%s\n",tmpBuf);
printf("tmpBuf:%s\n",tmpBuf); send(sockfd, tmpBuf, strlen(tmpBuf), 0);
send(sockfd, tmpBuf, strlen(tmpBuf), 0); free(out);
cJSON_Delete(root); free(tmpBuf);
free(out); return 0;
free(tmpBuf);
return 0;
} }
static int _kk_send_data_to_sdk(char *nodeid,char *opcode,char *arg) static int _kk_send_data_to_sdk(char *nodeid,char *opcode,cJSON *arg)
{ {
cJSON *root; cJSON *root;
char *out = NULL; char *out = NULL;
root=cJSON_CreateObject(); root=cJSON_CreateObject();
if(root){ if(root){
cJSON_AddStringToObject(root, "nodeid", nodeid); cJSON_AddStringToObject(root, "nodeid", nodeid);
cJSON_AddStringToObject(root, "opcode", opcode); cJSON_AddStringToObject(root, "opcode", opcode);
cJSON_AddStringToObject(root, "status", "success"); cJSON_AddStringToObject(root, "status", "success");
cJSON_AddStringToObject(root, "arg", arg); cJSON_AddItemToObject(root,"arg",arg);
out=cJSON_Print(root); out=cJSON_Print(root);
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
printf("out:%s\n",out); printf("out:%s\n",out);
cJSON_Minify((char*)out); cJSON_Minify((char*)out);
kk_send_data_to_sdk(out); kk_send_data_to_sdk(out);
} }
free(arg);
cJSON_Delete(root); cJSON_Delete(root);
return 0; return 0;
} }
static int kk_heartbeat_ack(int sockfd) static int kk_heartbeat_ack(int sockfd)
{ {
cJSON *root; cJSON *root;
root=cJSON_CreateObject(); root=cJSON_CreateObject();
if(root){ if(root){
cJSON_AddStringToObject(root, "nodeid", "*"); cJSON_AddStringToObject(root, "nodeid", "*");
cJSON_AddStringToObject(root, "opcode", HEARTBEAT_OPCODE); cJSON_AddStringToObject(root, "opcode", HEARTBEAT_OPCODE);
cJSON_AddStringToObject(root, "status", "success"); cJSON_AddStringToObject(root, "status", "success");
cJSON_AddStringToObject(root, "arg", "*"); cJSON_AddStringToObject(root, "arg", "*");
kk_send_ack(root,sockfd); kk_send_ack(root,sockfd);
} }
cJSON_Delete(root); cJSON_Delete(root);
return 0; return 0;
} }
static int kk_loginccu_ack(cJSON *arg,int sockfd) static int kk_loginccu_ack(cJSON *arg,int sockfd)
{ {
cJSON *zkid; cJSON *zkid;
cJSON *root; cJSON *root;
cJSON *args; cJSON *args;
char *out = NULL; char *out = NULL;
char *tmpBuf = NULL; char *tmpBuf = NULL;
if(arg == NULL){ if(arg == NULL){
return -1; return -1;
} }
zkid = cJSON_GetObjectItem(arg, ZKID_STRING); zkid = cJSON_GetObjectItem(arg, ZKID_STRING);
if(zkid != NULL){ if(zkid != NULL){
if(strstr(KK_CCU_ID,zkid->valuestring) != NULL){ if(strstr(KK_CCU_ID,zkid->valuestring) != NULL){
root=cJSON_CreateObject(); root=cJSON_CreateObject();
if(root){ if(root){
args = cJSON_CreateObject(); args = cJSON_CreateObject();
if(args){ if(args){
cJSON_AddItemToObject(root, "arg", args); cJSON_AddItemToObject(root, "arg", args);
cJSON_AddStringToObject(args, "error_code", "0"); cJSON_AddStringToObject(args, "error_code", "0");
cJSON_AddStringToObject(args, "seq", ""); cJSON_AddStringToObject(args, "seq", "");
cJSON_AddStringToObject(args, "zkid", zkid->valuestring); cJSON_AddStringToObject(args, "zkid", zkid->valuestring);
} }
cJSON_AddStringToObject(root, "nodeid", "*"); cJSON_AddStringToObject(root, "nodeid", "*");
cJSON_AddStringToObject(root, "opcode", LOGIN_OPCODE); cJSON_AddStringToObject(root, "opcode", LOGIN_OPCODE);
cJSON_AddStringToObject(root, "status", "success"); cJSON_AddStringToObject(root, "status", "success");
kk_send_ack(root,sockfd); kk_send_ack(root,sockfd);
} }
cJSON_Delete(root); cJSON_Delete(root);
} }
}else{ }else{
ERROR_PRINT("data error...\n"); ERROR_PRINT("data error...\n");
return -1; return -1;
} }
return 0; return 0;
} }
int kk_data_handle(cJSON *json,int sockfd)
//构建hw信息
static cJSON *kk_zb_dev_hw_info_build(const char *deviceCode,cJSON * productCode,cJSON * online,const char *hw_ver,const char *sw_ver)
{ {
cJSON *opcode; cJSON *item;
cJSON *arg; char mac[32] = {0};
opcode = cJSON_GetObjectItem(json, OPCODE_STRING); int online_status = 0;
if(opcode != NULL){ int pid;
if(strcmp(opcode->valuestring,LOGIN_OPCODE) == 0){ if(mac==NULL){
arg = cJSON_GetObjectItem(json, ARG_STRING); return NULL;
kk_loginccu_ack(arg,sockfd); }
}else if(strcmp(opcode->valuestring,HEARTBEAT_OPCODE) == 0){
kk_heartbeat_ack(sockfd); item = cJSON_CreateObject();
}else if(strcmp(opcode->valuestring,SYNC_OPCODE) == 0){ if(item){
kk_handle_sync_info(); if(hw_ver!=NULL){
} cJSON_AddStringToObject(item, "hardware_version", hw_ver);
} }else{
return 0; cJSON_AddStringToObject(item, "hardware_version", "");
}
_deviceCode_switchto_mac(deviceCode,mac);
if(online==0){
online_status = 1; //在线
}else if(online==1){
online_status = 2; //离线
}else{
online_status = 0; //未知
}
pid = atoi(productCode);
cJSON_AddStringToObject(item, "mac", mac);
cJSON_AddNumberToObject(item, "online_status",online_status);
cJSON_AddNumberToObject(item, "product_id", pid);
if(hw_ver!=NULL){
cJSON_AddStringToObject(item, "version", sw_ver);
}else{
cJSON_AddStringToObject(item, "version", "");
}
}
return item;
}
static void _kk_zb_devs_hw_ack(int sockfd,cJSON *arg)
{
cJSON *root;
root=cJSON_CreateObject();
if(root){
cJSON_AddStringToObject(root, "nodeid", "*");
cJSON_AddStringToObject(root, "opcode", GET_ZB_DEVS_HW_INFO_OPCODE);
cJSON_AddStringToObject(root, "status", "success");
cJSON_AddItemToObject(root, "arg", arg);
kk_send_ack(root,sockfd);
}
cJSON_Delete(root);
}
int kk_zb_devs_hw_ack_all(int sockfd)
{
kk_map_dev_ctx *ctx = _kk_map_dev_ctx();
kk_map_dev_node_t *search_node = NULL;
cJSON *array = cJSON_CreateArray();
cJSON *item;
list_for_each_entry(search_node, &ctx->dev_list, linked_list, kk_map_dev_node_t) {
if((item = kk_zb_dev_hw_info_build(search_node->deviceCode,search_node->productCode,search_node->online_status,NULL,NULL))!=NULL){
cJSON_AddItemToArray(array,item);
}
}
_kk_zb_devs_hw_ack(sockfd,array);
return -1;
}
int kk_zb_dev_hw_info_build_by_deviceCode(int sockfd,const char *deviceCode)
{
kk_map_dev_ctx *ctx = _kk_map_dev_ctx();
kk_map_dev_node_t *search_node = NULL;
cJSON *item;
unsigned char online_status = 0;
int pid =-1;
list_for_each_entry(search_node, &ctx->dev_list, linked_list, kk_map_dev_node_t) {
if ( (strlen(search_node->deviceCode) == strlen(deviceCode)) &&
(memcmp(search_node->deviceCode, deviceCode, strlen(deviceCode)) == 0)) {
item = kk_zb_dev_hw_info_build(search_node->deviceCode,search_node->productCode,search_node->online_status,NULL,NULL);
return item;
}
}
return NULL;
}
static void kk_zb_devs_hw_ack(int sockfd,cJSON *conditions)
{
int i,size;
cJSON *type;
cJSON *arg;
char devCode[33] ={0};
type = cJSON_GetObjectItem(conditions,"condition_type");
if(type==NULL){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_zb_devs_hw_ack_all(sockfd);
}else{
if(strcmp(type->valuestring,"dev_list")){
WARNING_PRINT("[type err]%s,%s\n",type->valuestring,"dev_list");
return ;
}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
arg = cJSON_GetObjectItem(conditions,"condition_arg");
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
size = cJSON_GetArraySize(arg);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON *qMac;
cJSON *item;
cJSON *array = cJSON_CreateArray();
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
for(i=0;i<size;i++){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
qMac=cJSON_GetArrayItem(arg,1);
if(mac_switchto_deviceCode(qMac->valuestring,devCode)==0){
if((item=kk_zb_dev_hw_info_build_by_deviceCode(sockfd,devCode))!=NULL){
cJSON_AddItemToArray(array,item);
}
}
}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
_kk_zb_devs_hw_ack(sockfd,array);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
}
return 0;
}
int kk_data_handle(cJSON *json,int sockfd)
{
cJSON *opcode;
cJSON *arg;
opcode = cJSON_GetObjectItem(json, OPCODE_STRING);
if(opcode != NULL){
if(strcmp(opcode->valuestring,LOGIN_OPCODE) == 0){
arg = cJSON_GetObjectItem(json, ARG_STRING);
kk_loginccu_ack(arg,sockfd);
}else if(strcmp(opcode->valuestring,HEARTBEAT_OPCODE) == 0){
kk_heartbeat_ack(sockfd);
}else if(strcmp(opcode->valuestring,SYNC_OPCODE) == 0){
kk_handle_sync_info();
}else if(strcmp(opcode->valuestring,GET_ZB_DEVS_HW_INFO_OPCODE) == 0){
cJSON *conditions = cJSON_GetObjectItem(json, OPCODE_STRING);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_zb_devs_hw_ack(sockfd,conditions);
}else{
kk_ccu_opcode_handle(json);
}
}
return 0;
} }
static int kk_parse_syncinfo(cJSON *payload) static int kk_parse_syncinfo(cJSON *payload)
{ {
cJSON *paramStr,*dataStr; cJSON *paramStr,*dataStr;
cJSON *gwdevices,*subdevices; cJSON *gwdevices,*subdevices;
cJSON * gwitem,*properties; cJSON * gwitem,*properties;
char *gwdevicecode; cJSON *onlineStatus;
char *deviceCode,*productCode; char *gwdevicecode;
char *identifier,*valuetype; char *deviceCode,*productCode;
cJSON * subitem; char *identifier,*valuetype;
cJSON * newccuItem; cJSON * subitem;
cJSON *valuejson; cJSON * newccuItem;
int value; cJSON *valuejson;
printf("[%s][%d]\n",__FUNCTION__,__LINE__); int value;
kk_map_dev_node_t *node = NULL; printf("\n\n\n00000000000000000000000000000000000000\n\n\n");
printf("[%s][%d]\n",__FUNCTION__,__LINE__); kk_map_dev_deinit();
paramStr = cJSON_GetObjectItem(payload, DATA_STRING); printf("\n\n\n11111111111111111111111111111111111\n\n\n");
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if(paramStr == NULL) return -1; kk_map_dev_node_t *node = NULL;
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
dataStr = cJSON_GetObjectItem(paramStr, DATA_STRING); paramStr = cJSON_GetObjectItem(payload, DATA_STRING);
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if(dataStr == NULL) return -1; if(paramStr == NULL) return -1;
gwdevices = cJSON_GetObjectItem(dataStr, DEVICES_STRING); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
printf("[%s][%d]\n",__FUNCTION__,__LINE__); dataStr = cJSON_GetObjectItem(paramStr, DATA_STRING);
if(gwdevices == NULL) return -1; printf("[%s][%d]\n",__FUNCTION__,__LINE__);
gwitem = gwdevices->child; if(dataStr == NULL) return -1;
printf("[%s][%d]\n",__FUNCTION__,__LINE__); gwdevices = cJSON_GetObjectItem(dataStr, DEVICES_STRING);
while(gwitem != NULL){ printf("[%s][%d]\n",__FUNCTION__,__LINE__);
printf("[%s][%d]\n",__FUNCTION__,__LINE__); if(gwdevices == NULL) return -1;
subdevices = cJSON_GetObjectItem(gwitem,DEVICES_STRING); gwitem = gwdevices->child;
gwdevicecode = cJSON_GetObjectItem(gwitem,MSG_DEVICE_CODE_STR)->valuestring; printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if(subdevices != NULL){ printf("\n\n222222222222222222222222222222222\n\n\n");
printf("[%s][%d]\n",__FUNCTION__,__LINE__); while(gwitem != NULL){
subitem = subdevices->child; printf("[%s][%d]\n",__FUNCTION__,__LINE__);
while(subitem != NULL){ subdevices = cJSON_GetObjectItem(gwitem,DEVICES_STRING);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
deviceCode = cJSON_GetObjectItem(subitem,MSG_DEVICE_CODE_STR)->valuestring; gwdevicecode = cJSON_GetObjectItem(gwitem,MSG_DEVICE_CODE_STR)->valuestring;
productCode = cJSON_GetObjectItem(subitem,MSG_PRODUCT_CODE_STR)->valuestring; if(subdevices != NULL){
properties = cJSON_GetObjectItem(subitem,MSG_PROPERTIES_STR); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
printf("[%s][%d]\n",__FUNCTION__,__LINE__); subitem = subdevices->child;
node = kk_map_dev_add(deviceCode,productCode,gwdevicecode);
if(node != NULL && node->newccu != NULL){
newccuItem = node->newccu->child; while(subitem != NULL){
while(newccuItem != NULL){ printf("[%s][%d]\n",__FUNCTION__,__LINE__);
identifier = cJSON_GetObjectItem(newccuItem,MSG_INDENTIFIER_STR)->valuestring; deviceCode = cJSON_GetObjectItem(subitem,MSG_DEVICE_CODE_STR)->valuestring;
valuetype = cJSON_GetObjectItem(newccuItem,MSG_INDENTIFIER_STR)->valuestring; printf("[%s][%d]\n",__FUNCTION__,__LINE__);
valuejson = cJSON_GetObjectItem(properties,identifier);
if(valuejson != NULL){ productCode = cJSON_GetObjectItem(subitem,MSG_PRODUCT_CODE_STR)->valuestring;
if(strcmp(valuetype,"bool") == 0 || strcmp(valuetype,"int") == 0){ printf("[%s][%d]\n",__FUNCTION__,__LINE__);
value = valuejson->valueint;
printf("[%s][%d]\n",__FUNCTION__,__LINE__); onlineStatus = cJSON_GetObjectItem(subitem,MSG_ONLINE_STATUS_STR);
kk_map_dev_update_int_value(node,identifier,value); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
}
} properties = cJSON_GetObjectItem(subitem,MSG_PROPERTIES_STR);
newccuItem = newccuItem->next;
}
} printf("[%s][%d]\n",__FUNCTION__,__LINE__);
subitem = subitem->next;
}
}
gwitem = gwitem->next; node = kk_map_dev_add(deviceCode,productCode,gwdevicecode,onlineStatus->valuestring);
}
return 0; property_syn_deal(deviceCode,properties);
subitem = subitem->next;
}
}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
gwitem = gwitem->next;
}
printf("\n\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n\n\n");
return 0;
} }
static int kk_create_floors_to_sdk(cJSON *root) static int kk_create_floors_to_sdk(cJSON *root)
{ {
cJSON *floors = cJSON_CreateArray(); cJSON *floors = cJSON_CreateArray();
cJSON *floorItem = cJSON_CreateObject(); cJSON *floorItem = cJSON_CreateObject();
cJSON_AddStringToObject(floorItem, "floor_icon", ""); cJSON_AddStringToObject(floorItem, "floor_icon", "");
cJSON_AddStringToObject(floorItem, "floor_pos", "1"); cJSON_AddStringToObject(floorItem, "floor_pos", "1");
cJSON_AddStringToObject(floorItem, "id", "1"); cJSON_AddStringToObject(floorItem, "id", "1");
cJSON_AddStringToObject(floorItem, "name", "一楼"); cJSON_AddStringToObject(floorItem, "name", "一楼");
cJSON_AddItemToArray(floors, floorItem); cJSON_AddItemToArray(floors, floorItem);
cJSON_AddItemToObject(root, "floors", floors); cJSON_AddItemToObject(root, "floors", floors);
return 0; return 0;
} }
static int kk_create_roominfo_to_sdk(cJSON *root) static int kk_create_roominfo_to_sdk(cJSON *root)
{ {
cJSON *rooms = cJSON_CreateArray(); cJSON *rooms = cJSON_CreateArray();
cJSON *roomsItem = cJSON_CreateObject(); cJSON *roomsItem = cJSON_CreateObject();
cJSON *room_status; cJSON *room_status;
cJSON_AddStringToObject(roomsItem, "floor_id", "1"); cJSON_AddStringToObject(roomsItem, "floor_id", "1");
cJSON_AddStringToObject(roomsItem, "id", "1"); cJSON_AddStringToObject(roomsItem, "id", "1");
cJSON_AddStringToObject(roomsItem, "room_icon", ""); cJSON_AddStringToObject(roomsItem, "room_icon", "");
cJSON_AddStringToObject(roomsItem, "name", "卧室"); cJSON_AddStringToObject(roomsItem, "name", "卧室");
room_status = cJSON_CreateObject(); room_status = cJSON_CreateObject();
cJSON_AddItemToObject(roomsItem, "room_status", room_status); cJSON_AddItemToObject(roomsItem, "room_status", room_status);
cJSON_AddItemToArray(rooms, roomsItem); cJSON_AddItemToArray(rooms, roomsItem);
cJSON_AddItemToObject(root, "rooms", rooms); cJSON_AddItemToObject(root, "rooms", rooms);
return 0; return 0;
} }
static int kk_create_scene_to_sdk(cJSON *root) static int kk_create_scene_to_sdk(cJSON *root)
{ {
cJSON *scenes = cJSON_CreateArray(); cJSON *scenes = cJSON_CreateArray();
cJSON_AddItemToObject(root, "scenes", scenes); cJSON_AddItemToObject(root, "scenes", scenes);
return 0; return 0;
} }
int kk_create_syncinfo_to_sdk(void) int kk_create_syncinfo_to_sdk(void)
{ {
cJSON *air_box_devices; cJSON *air_box_devices;
cJSON *alarms; cJSON *alarms;
cJSON *ccu_link_status; cJSON *ccu_link_status;
cJSON *link_arg; cJSON *link_arg;
cJSON *ccu_version; cJSON *ccu_version;
cJSON *central_ac_gws; cJSON *central_ac_gws;
cJSON *central_ac_indoorunits; cJSON *central_ac_indoorunits;
cJSON *cnwise_music_controllers; cJSON *cnwise_music_controllers;
cJSON *code_lib_controllers; cJSON *code_lib_controllers;
cJSON *controllers; cJSON *controllers;
cJSON *expand_rules; cJSON *expand_rules;
cJSON *group; cJSON *group;
cJSON *guard; cJSON *guard;
cJSON *gw_version; cJSON *gw_version;
char *out = NULL; char *out = NULL;
cJSON *root=cJSON_CreateObject();
cJSON *aiks_controllers = cJSON_CreateArray(); cJSON *root=cJSON_CreateObject();
cJSON_AddItemToObject(root, "aiks_controllers", aiks_controllers); cJSON *aiks_controllers = cJSON_CreateArray();
air_box_devices = cJSON_CreateArray(); cJSON_AddItemToObject(root, "aiks_controllers", aiks_controllers);
cJSON_AddItemToObject(root, "air_box_devices", air_box_devices); air_box_devices = cJSON_CreateArray();
alarms = cJSON_CreateArray(); cJSON_AddItemToObject(root, "air_box_devices", air_box_devices);
cJSON_AddItemToObject(root, "alarms", alarms); alarms = cJSON_CreateArray();
ccu_link_status = cJSON_CreateObject(); cJSON_AddItemToObject(root, "alarms", alarms);
link_arg = cJSON_CreateObject(); ccu_link_status = cJSON_CreateObject();
cJSON_AddItemToObject(ccu_link_status, "link_arg", link_arg); link_arg = cJSON_CreateObject();
cJSON_AddStringToObject(ccu_link_status, "link_type", "broadband_net"); cJSON_AddItemToObject(ccu_link_status, "link_arg", link_arg);
cJSON_AddItemToObject(root, "ccu_link_status", ccu_link_status); cJSON_AddStringToObject(ccu_link_status, "link_type", "broadband_net");
ccu_version = cJSON_CreateObject(); cJSON_AddItemToObject(root, "ccu_link_status", ccu_link_status);
cJSON_AddStringToObject(ccu_version, "cur_ccu_version", "1.0.0"); ccu_version = cJSON_CreateObject();
cJSON_AddStringToObject(ccu_version, "downloaded_ccu_version", "1.0.0"); cJSON_AddStringToObject(ccu_version, "cur_ccu_version", "1.0.0");
cJSON_AddItemToObject(root, "ccu_version", ccu_version); cJSON_AddStringToObject(ccu_version, "downloaded_ccu_version", "1.0.0");
central_ac_gws = cJSON_CreateArray(); cJSON_AddItemToObject(root, "ccu_version", ccu_version);
cJSON_AddItemToObject(root, "central_ac_gws", central_ac_gws); central_ac_gws = cJSON_CreateArray();
central_ac_indoorunits = cJSON_CreateArray(); cJSON_AddItemToObject(root, "central_ac_gws", central_ac_gws);
cJSON_AddItemToObject(root, "central_ac_indoorunits", central_ac_indoorunits); central_ac_indoorunits = cJSON_CreateArray();
cnwise_music_controllers = cJSON_CreateArray(); cJSON_AddItemToObject(root, "central_ac_indoorunits", central_ac_indoorunits);
cJSON_AddItemToObject(root, "cnwise_music_controllers", cnwise_music_controllers); cnwise_music_controllers = cJSON_CreateArray();
code_lib_controllers = cJSON_CreateArray(); cJSON_AddItemToObject(root, "cnwise_music_controllers", cnwise_music_controllers);
cJSON_AddItemToObject(root, "code_lib_controllers", code_lib_controllers); code_lib_controllers = cJSON_CreateArray();
cJSON_AddItemToObject(root, "code_lib_controllers", code_lib_controllers);
controllers = cJSON_CreateArray();
cJSON_AddItemToObject(root, "controllers", controllers); controllers = cJSON_CreateArray();
cJSON_AddItemToObject(root, "controllers", controllers);
kk_create_devicestatus_to_sdk(root);
kk_create_devices_to_sdk(root); kk_create_devicestatus_to_sdk(root);
#if 1
printf("[%s][%d]\n",__FUNCTION__,__LINE__); kk_create_devices_to_sdk(root);
expand_rules = cJSON_CreateArray();
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON_AddItemToObject(root, "expand_rules", expand_rules); #if 1
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_create_floors_to_sdk(root); expand_rules = cJSON_CreateArray();
group = cJSON_CreateArray(); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
printf("[%s][%d]\n",__FUNCTION__,__LINE__); cJSON_AddItemToObject(root, "expand_rules", expand_rules);
cJSON_AddItemToObject(root, "group", group); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
printf("[%s][%d]\n",__FUNCTION__,__LINE__); kk_create_floors_to_sdk(root);
guard = cJSON_CreateObject(); group = cJSON_CreateArray();
cJSON_AddItemToObject(root, "guard", guard); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
gw_version = cJSON_CreateObject(); cJSON_AddItemToObject(root, "group", group);
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON_AddItemToObject(root, "gw_version", gw_version); guard = cJSON_CreateObject();
printf("[%s][%d]\n",__FUNCTION__,__LINE__); cJSON_AddItemToObject(root, "guard", guard);
kk_create_roominfo_to_sdk(root); gw_version = cJSON_CreateObject();
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_create_scene_to_sdk(root); cJSON_AddItemToObject(root, "gw_version", gw_version);
#endif printf("[%s][%d]\n",__FUNCTION__,__LINE__);
printf("[%s][%d]\n",__FUNCTION__,__LINE__); kk_create_roominfo_to_sdk(root);
out=cJSON_Print(root); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
printf("[%s][%d]\n",__FUNCTION__,__LINE__); kk_create_scene_to_sdk(root);
printf("out:%s\n",out); #endif
cJSON_Minify((char*)out); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
_kk_send_data_to_sdk("*","*",out); out=cJSON_Print(root);
return 0; printf("[%s][%d]\n",__FUNCTION__,__LINE__);
printf("out:%s\n",out);
_kk_send_data_to_sdk("*","SYNC_INFO",root);
return 0;
} }
void KK_Data_FromMid(void* str,int len) void KK_Data_FromMid(void* str,int len)
{ {
cJSON *json; cJSON *json;
cJSON *info_root; cJSON *info_root;
cJSON *payload,*typeJson; cJSON *payload,*typeJson;
cJSON *deviceCode;
printf("str:%s\n",str); printf("[midware->lan]:%s\n",str);
json = cJSON_Parse(str);
if(json == NULL){
return;
}
info_root = cJSON_GetObjectItem(json, MSG_INFO_STR);
json = cJSON_Parse(str);
if(json == NULL){
return;
}
info_root = cJSON_GetObjectItem(json, MSG_INFO_STR);
if(info_root == NULL) return; if(info_root == NULL) return;
payload = cJSON_GetObjectItem(json, MSG_PAYLOAD_STR); payload = cJSON_GetObjectItem(json, MSG_PAYLOAD_STR);
if(payload == NULL) return;
if(payload == NULL) return;
deviceCode= cJSON_GetObjectItem(info_root, MSG_DEVICE_CODE_STR);
if(deviceCode == NULL) return;
typeJson = cJSON_GetObjectItem(info_root, MSG_TYPE_STR); typeJson = cJSON_GetObjectItem(info_root, MSG_TYPE_STR);
if(typeJson == NULL) return; if(typeJson == NULL) return;
if (strstr(typeJson->valuestring,SYNC_MSG_TYPE_REPLY) != NULL){ if (strstr(typeJson->valuestring,SYNC_MSG_TYPE_REPLY) != NULL){
kk_parse_syncinfo(payload); kk_parse_syncinfo(payload);
kk_create_syncinfo_to_sdk(); kk_create_syncinfo_to_sdk();
} printf("TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n");
} }else if((typeJson->valuestring,"/thing/event/property/post")!= NULL){
\ No newline at end of file property_post_deal(deviceCode->valuestring,payload);
}
}
...@@ -3,270 +3,400 @@ ...@@ -3,270 +3,400 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "kk_data_mng.h" #include "kk_data_mng.h"
#include "kk_lan_node_db.h"
static kk_map_dev_ctx g_map_dev_mgr = {0}; static kk_map_dev_ctx g_map_dev_mgr = {0};
static kk_map_dev_ctx *_kk_map_dev_ctx(void)
kk_map_dev_ctx *_kk_map_dev_ctx(void)
{ {
return &g_map_dev_mgr; return &g_map_dev_mgr;
} }
static void _kk_map_dev_mutex_lock(void) static void _kk_map_dev_mutex_lock(void)
{ {
kk_map_dev_ctx *ctx = _kk_map_dev_ctx(); kk_map_dev_ctx *ctx = _kk_map_dev_ctx();
if (ctx->mutex) { if (ctx->mutex) {
kk_MutexLock(ctx->mutex); kk_MutexLock(ctx->mutex);
} }
} }
static void _kk_map_dev_mutex_unlock(void) static void _kk_map_dev_mutex_unlock(void)
{ {
kk_map_dev_ctx *ctx = _kk_map_dev_ctx(); kk_map_dev_ctx *ctx = _kk_map_dev_ctx();
if (ctx->mutex) { if (ctx->mutex) {
kk_MutexUnLock(ctx->mutex); kk_MutexUnLock(ctx->mutex);
} }
} }
int kk_map_dev_init(void) int kk_map_dev_init(void)
{ {
kk_map_dev_ctx *ctx = _kk_map_dev_ctx(); kk_map_dev_ctx *ctx = _kk_map_dev_ctx();
memset(ctx, 0, sizeof(kk_map_dev_ctx)); memset(ctx, 0, sizeof(kk_map_dev_ctx));
ctx->mutex = kk_MutexCreate(); ctx->mutex = kk_MutexCreate();
if (ctx->mutex == NULL) { if (ctx->mutex == NULL) {
return -1; return -1;
} }
INIT_LIST_HEAD(&ctx->dev_list); INIT_LIST_HEAD(&ctx->dev_list);
return 0; return 0;
} }
void kk_map_dev_deinit(void)
{
kk_map_dev_ctx *ctx = _kk_map_dev_ctx();
kk_map_dev_node_t *node = NULL;
kk_map_dev_node_t *n = NULL;
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
list_for_each_entry_safe(node,n,&ctx->dev_list, linked_list, kk_map_dev_node_t) {
printf("[remove list] node->linked_list000000000\n");
if (node != NULL) {
_kk_map_dev_mutex_lock();
if(node->json){
printf("[delete cjson] node->json.\n");
cJSON_Delete(node->json);
}
if(node->syn_opcode) {
printf("[free] node->syn_opcode.\n");
free(node->syn_opcode);
}
printf("[remove list] node->linked_list\n");
dlist_del(&node->linked_list);
memset(node,0,sizeof(kk_map_dev_node_t));
_kk_map_dev_mutex_unlock();
}
}
}
static int kk_open_cfg_file(char *deviceCode,kk_map_dev_node_t *node) static int kk_open_cfg_file(char *deviceCode,kk_map_dev_node_t *node)
{ {
char path[128] = {0}; char path[128] = {0};
unsigned int filesize; unsigned int filesize;
FILE *fp; FILE *fp;
char *buf = NULL; char *buf = NULL;
cJSON *json = NULL; cJSON *json = NULL;
cJSON *optype = NULL; cJSON *optype = NULL;
sprintf(path,KK_DEVICE_MAP_FILE_PATH,deviceCode); cJSON *syn_type = NULL;
printf("kk_open_cfg_file path:%s\n",path);
sprintf(path,KK_DEVICE_MAP_FILE_PATH,deviceCode);
printf("kk_open_cfg_file path:%s\n",path);
if(!(fp = fopen(path,"r"))) if(!(fp = fopen(path,"r")))
{ {
ERROR_PRINT("can't open the file tslPath:%s\n",path); ERROR_PRINT("can't open the file tslPath:%s\n",path);
return -1; return -1;
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
fseek(fp, 0L, SEEK_END); fseek(fp, 0L, SEEK_END);
filesize = ftell(fp); filesize = ftell(fp);
buf = malloc(filesize+1); buf = malloc(filesize+1);
if(buf == NULL) if(buf == NULL)
{ {
ERROR_PRINT("MALLOC FAIL!!!\n"); ERROR_PRINT("MALLOC FAIL!!!\n");
fclose(fp); fclose(fp);
return -1; return -1;
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
memset(buf,0x0,filesize+1); memset(buf,0x0,filesize+1);
fseek(fp, 0L, SEEK_SET); fseek(fp, 0L, SEEK_SET);
fread(buf, 1, filesize, fp); fread(buf, 1, filesize, fp);
printf("buf:%s\n",buf); printf("buf:%s\n",buf);
json = cJSON_Parse(buf); json = cJSON_Parse(buf);
if(json == NULL){ if(json == NULL){
ERROR_PRINT("cJSON_Parse FAIL!!!\n"); ERROR_PRINT("cJSON_Parse FAIL!!!\n");
free(buf); free(buf);
fclose(fp); fclose(fp);
return -1; return -1;
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__); node->json = json;
optype = cJSON_GetObjectItem(json, OPEARTETYPE_STRING);
if(optype != NULL){ printf("[%s][%d]\n",__FUNCTION__,__LINE__);
memcpy(node->opearteType,optype->valuestring,strlen(optype->valuestring)); optype = cJSON_GetObjectItem(json, OPEARTETYPE_STRING);
} if(optype != NULL){
printf("[%s][%d]\n",__FUNCTION__,__LINE__); memcpy(node->opearteType,optype->valuestring,strlen(optype->valuestring));
node->channelNum = cJSON_GetObjectItem(json, CHANNEL_STRING)->valueint; }
printf("[%s][%d]\n",__FUNCTION__,__LINE__); syn_type = cJSON_GetObjectItem(json, "syn_type");
node->newccu = cJSON_GetObjectItem(json, NEWCCU_STRING); if(syn_type){
printf("[%s][%d]\n",__FUNCTION__,__LINE__); cJSON *syn_opcode = cJSON_GetObjectItem(json, "syn_opcode");
node->oldccu = cJSON_GetObjectItem(json, OLDCCU_STRING); node->syn_type = syn_type->valueint;
printf("[%s][%d]\n",__FUNCTION__,__LINE__); node->syn_opcode= (char *)malloc(strlen(syn_opcode->valuestring)+1);
if(node->newccu == NULL || node->oldccu == NULL){ memset(node->syn_opcode,0,strlen(node->syn_opcode)+1);
ERROR_PRINT("cJSON_Parse DATA FAIL!!!\n"); memcpy(node->syn_opcode,syn_opcode->valuestring,strlen(syn_opcode->valuestring));
free(buf); }
fclose(fp); printf("[%s][%d]node->syn_type=%d****************\n",__FUNCTION__,__LINE__,node->syn_type);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
node->channelNum = cJSON_GetObjectItem(json, CHANNEL_STRING)->valueint;
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
node->newccu = cJSON_GetObjectItem(json, NEWCCU_STRING);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
node->oldccu = cJSON_GetObjectItem(json, OLDCCU_STRING);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if(node->newccu == NULL || node->oldccu == NULL){
ERROR_PRINT("cJSON_Parse DATA FAIL!!!\n");
free(buf);
fclose(fp);
return -1; return -1;
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
free(buf); free(buf);
fclose(fp); fclose(fp);
return 0; return 0;
} }
static int kk_creater_nodeid(char *deviceCode,char *channel,char *nodeId) int kk_creater_nodeid(char *deviceCode,int channel,char *nodeId)
{ {
if(deviceCode == NULL || channel == NULL || nodeId == NULL){ static int next = 1;
return -1; int node=-1;
}
strcat(nodeId,deviceCode); if(deviceCode == NULL || channel == NULL || nodeId == NULL){
strcat(nodeId,"_"); printf("bbb\n");
strcat(nodeId,channel); return -1;
printf("nodeId:%s\n",nodeId); }
return 0; printf("aaa\n");
printf("channel=%d\n",channel);
printf("deviceCode=%s\n",deviceCode);
printf(",,,,\n");
//INFO_PRINT("-------------->deviceCode=%s,channel=%d\n",deviceCode,channel);
printf("aaa-1\n");
if(kk_check_lan_node_exist(deviceCode,channel)){
printf("aaa-2\n");
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
node = kk_lan_db_node_get(deviceCode,channel);
}else{
printf("aaa-3\n");
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
while(kk_check_lan_node(next)){
++next;
}
INFO_PRINT("#################next=%d\n",next);
if(0==kk_lan_db_node_insert(deviceCode,channel,next)){
node=next;
}
}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
printf("aaa-44,node=%d\n",node);
sprintf(nodeId,"%d",node);
printf("aaa-4\n");
//INFO_PRINT("[node]deviceCode=%s,channel=%d,node=%d,nodeId=%s\n",deviceCode,channel,node,nodeId);
return 0;
} }
/******************************************
*从映射表中获取组件所需的值
*******************************************/
static char* kk_value_int_map_string(char *opcodemap,kk_map_dev_node_t *node,int idx) static char* kk_value_int_map_string(char *opcodemap,kk_map_dev_node_t *node,int idx)
{ {
if(opcodemap == NULL || node == NULL){ if(opcodemap == NULL || node == NULL){
return -1; return -1;
} }
cJSON * oldccuItem = node->oldccu->child; cJSON * oldccuItem = node->oldccu->child;
while(oldccuItem != NULL){ while(oldccuItem != NULL){
char *opcode = cJSON_GetObjectItem(oldccuItem,OPCODE_STRING)->valuestring; char *opcode = cJSON_GetObjectItem(oldccuItem,OPCODE_STRING)->valuestring;
char *dataType = cJSON_GetObjectItem(oldccuItem,DATATYPE_STRING)->valuestring; char *dataType = cJSON_GetObjectItem(oldccuItem,DATATYPE_STRING)->valuestring;
if(strcmp(opcode,opcodemap) == 0){ if(strcmp(opcode,opcodemap) == 0){
cJSON *range = cJSON_GetObjectItem(oldccuItem,VALUERANGE_STRING); cJSON *range = cJSON_GetObjectItem(oldccuItem,VALUERANGE_STRING);
if(range != NULL){ if(range != NULL){
cJSON * pSub = cJSON_GetArrayItem(range, idx); cJSON * pSub = cJSON_GetArrayItem(range, idx);
if(pSub != NULL){ if(pSub != NULL){
if(strcmp(dataType,"string") == 0){ if(strcmp(dataType,"string") == 0){
return pSub->valuestring; return pSub->valuestring;
} }
} }
} }
}
} }
return "";
} }
return ""; int kk_get_int_value_idx(cJSON * range,int val)
{
int i = 0;
int array_size = cJSON_GetArraySize (range);
for(i = 0; i < array_size; i++){
cJSON * pSub = cJSON_GetArrayItem(range, i);
if(pSub != NULL && (pSub->valueint == val)){
return i;
}
}
return -1;
} }
static int kk_get_int_value_idx(cJSON * range,int val)
int mac_switchto_deviceCode(char *mac,char * deviceCode)
{ {
int i = 0; char mac_bak[33] = {0};
int array_size = cJSON_GetArraySize (range); int i, j;
for(i = 0; i < array_size; i++){ int len = strlen(mac);
cJSON * pSub = cJSON_GetArrayItem(range, i); if(len!=23)
if(pSub != NULL && pSub->valueint == val){ return -1;
return i;
} for(i=0; i < len; i++) /*将串s拷贝至串t*/
} mac_bak[i]=mac[i];
return -1; mac_bak[i]='\0';
for(i=0,j=0; i < len; i++){
if((i+1)%3==0&&i!=0){
continue;
}
deviceCode[j++] =mac_bak[i];
}
deviceCode[j]='\0'; /*在串s结尾加结束标志*/
return 0;
} }
static int _deviceCode_switchto_mac(char * deviceCode,char *mac) int _deviceCode_switchto_mac(char * deviceCode,char *mac)
{ {
char deviceCode_bak[33] = {0}; char deviceCode_bak[33] = {0};
int i, j; int i, j;
int len = strlen(deviceCode); int len = strlen(deviceCode);
for(i=0; i < len; i++) /*将串s拷贝至串t*/ for(i=0; i < len; i++) /*将串s拷贝至串t*/
deviceCode_bak[i]=deviceCode[i]; deviceCode_bak[i]=deviceCode[i];
deviceCode_bak[i]='\0'; deviceCode_bak[i]='\0';
for(i=0,j=0; i < len; i++){ for(i=0,j=0; i < len; i++){
if( i % 2 == 0 && i != 0) if( i % 2 == 0 && i != 0)
{ {
mac[j++]=':'; mac[j++]=':';
mac[j++]=deviceCode_bak[i]; mac[j++]=deviceCode_bak[i];
} }
else else
{ {
mac[j++]=deviceCode_bak[i]; mac[j++]=deviceCode_bak[i];
} }
} }
mac[j]='\0'; /*在串s结尾加结束标志*/ mac[j]='\0'; /*在串s结尾加结束标志*/
return 0; return 0;
} }
int kk_create_devices_to_sdk(cJSON *root) int kk_create_devices_to_sdk(cJSON *root)
{ {
kk_map_dev_node_t *node = NULL; kk_map_dev_node_t *node = NULL;
char nodeid[32] = {0}; char nodeid[32] = {0};
char channel[4] = {0}; char gwmac[32] = {0};
char gwmac[32] = {0}; char submac[32] = {0};
char submac[32] = {0}; char channel[4];
int idx = 1; int idx = 1;
kk_map_dev_ctx *ctx = _kk_map_dev_ctx();
cJSON *devices = cJSON_CreateArray();
list_for_each_entry(node, &ctx->dev_list, linked_list, kk_map_dev_node_t) {
if (node != NULL) {
for(idx = 1; idx <= node->channelNum; idx++){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON *subdevicesItem = cJSON_CreateObject();
sprintf(channel,"%d",idx);
cJSON_AddStringToObject(subdevicesItem, CHANNEL_STRING, channel);
cJSON_AddStringToObject(subdevicesItem, DEVICE_FIELD_STRING, "");
cJSON_AddStringToObject(subdevicesItem, DEVICE_FIELD_IDNDEX_STRING, "1");
cJSON_AddStringToObject(subdevicesItem, DEVICE_ICON_STRING, "");
cJSON_AddStringToObject(subdevicesItem, DEVICE_POS_STRING, "1");
_deviceCode_switchto_mac(node->gwDeviceCode,gwmac);
printf("gwmac:%s\n",gwmac);
cJSON_AddStringToObject(subdevicesItem, GW_MAC_STRING, gwmac);
_deviceCode_switchto_mac(node->deviceCode,submac);
cJSON_AddStringToObject(subdevicesItem, MAC_STRING, submac);
cJSON_AddStringToObject(subdevicesItem, NAME_STRING, "默认灯");
memset(nodeid,0x0,sizeof(nodeid));
kk_creater_nodeid(node->deviceCode,channel,nodeid);
cJSON_AddStringToObject(subdevicesItem, NODEID_STRING, nodeid);
cJSON_AddStringToObject(subdevicesItem, OPERATE_TYPE_STRING, node->opearteType);
cJSON_AddStringToObject(subdevicesItem, ROOM_ID_STRING, "1");
cJSON_AddItemToArray(devices, subdevicesItem);
}
} kk_map_dev_ctx *ctx = _kk_map_dev_ctx();
} cJSON *devices = cJSON_CreateArray();
cJSON_AddItemToObject(root, DEVICES_STRING, devices); list_for_each_entry(node, &ctx->dev_list, linked_list, kk_map_dev_node_t) {
return 0; if (node != NULL) {
for(idx = 1; idx <= node->channelNum; idx++){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON *subdevicesItem = cJSON_CreateObject();
sprintf(channel,"%d",idx);
cJSON_AddStringToObject(subdevicesItem, CHANNEL_STRING, channel);
cJSON_AddStringToObject(subdevicesItem, DEVICE_FIELD_STRING, "");
cJSON_AddStringToObject(subdevicesItem, DEVICE_FIELD_IDNDEX_STRING, "1");
cJSON_AddStringToObject(subdevicesItem, DEVICE_ICON_STRING, "");
cJSON_AddStringToObject(subdevicesItem, DEVICE_POS_STRING, "1");
_deviceCode_switchto_mac(node->gwDeviceCode,gwmac);
printf("gwmac:%s\n",gwmac);
cJSON_AddStringToObject(subdevicesItem, GW_MAC_STRING, gwmac);
_deviceCode_switchto_mac(node->deviceCode,submac);
cJSON_AddStringToObject(subdevicesItem, MAC_STRING, submac);
//todo name字段
cJSON_AddStringToObject(subdevicesItem, NAME_STRING, "默认灯");
memset(nodeid,0x0,sizeof(nodeid));
kk_creater_nodeid(node->deviceCode,idx,nodeid);
cJSON_AddStringToObject(subdevicesItem, NODEID_STRING, nodeid);
cJSON_AddStringToObject(subdevicesItem, OPERATE_TYPE_STRING, node->opearteType);
cJSON_AddStringToObject(subdevicesItem, ROOM_ID_STRING, "1");
cJSON_AddItemToArray(devices, subdevicesItem);
}
}
}
cJSON_AddItemToObject(root, DEVICES_STRING, devices);
return 0;
}
char *double_value_string(double val)
{
char *value = (char *)malloc(33);
memset(value,0,33);
snprintf(value,32,"%6f",val);
return value;
} }
int kk_create_devicestatus_to_sdk(cJSON *root) int kk_create_devicestatus_to_sdk(cJSON *root)
{ {
kk_map_dev_node_t *node = NULL;
char nodeid[32] = {0}; kk_map_dev_node_t *node = NULL;
char indxId[4] = {0}; char nodeid[32] = {0};
int idx = 1; char indxId[4] = {0};
kk_map_dev_ctx *ctx = _kk_map_dev_ctx(); int idx = 1;
cJSON *device_status = cJSON_CreateArray(); int syn_type = 0;
#if 1
list_for_each_entry(node, &ctx->dev_list, linked_list, kk_map_dev_node_t) { kk_map_dev_ctx *ctx = _kk_map_dev_ctx();
if (node != NULL) { cJSON *device_status = cJSON_CreateArray();
cJSON * newccuItem = node->newccu->child; cJSON *args;
while(newccuItem != NULL){ cJSON *sub_device;
cJSON *subdevicesItem = cJSON_CreateObject(); list_for_each_entry(node, &ctx->dev_list, linked_list, kk_map_dev_node_t){
memset(nodeid,0x0,sizeof(nodeid));
if(node->syn_type==1){
char *opcodemap = cJSON_GetObjectItem(newccuItem,OPCODEMAP_STRING)->valuestring; kk_creater_nodeid(node->deviceCode,1,nodeid);
char *channel = cJSON_GetObjectItem(newccuItem,CHANNEL_STRING)->valuestring;
char *dataType = cJSON_GetObjectItem(newccuItem,DATATYPE_STRING)->valuestring; if((args = kk_devicestatus_build(node))!=NULL){
cJSON *range = cJSON_GetObjectItem(newccuItem,VALUERANGE_STRING); sub_device=old_ccu_msg_build_json_node_int(atoi(nodeid),node->syn_opcode,NULL,args);
kk_creater_nodeid(node->deviceCode,channel,nodeid); if(sub_device){
cJSON_AddStringToObject(subdevicesItem, OPCODE_STRING, opcodemap); cJSON_AddItemToArray(device_status,sub_device);
cJSON_AddStringToObject(subdevicesItem, NODEID_STRING, nodeid); }
sprintf(indxId,"%d",idx++); }
cJSON_AddStringToObject(subdevicesItem, "index", indxId); }else{
kk_devicestatus_build_aaa(device_status,node);
if(strcmp(dataType,"int") == 0){ }
int value = cJSON_GetObjectItem(newccuItem,VALUE_STRING)->valueint; }
if(range != NULL){
int index = kk_get_int_value_idx(range,value); cJSON_AddItemToObject(root, DEVICE_STATUS_STRING, device_status);
cJSON_AddStringToObject(subdevicesItem, "arg", kk_value_int_map_string(opcodemap,node,index));
} return 0;
}
cJSON_AddItemToArray(device_status, subdevicesItem);
newccuItem = newccuItem->next;
}
}
}
#endif
cJSON_AddItemToObject(root, DEVICE_STATUS_STRING, device_status);
return 0;
} }
int kk_map_dev_update_int_value(kk_map_dev_node_t *node,char *identifier,int val) int kk_map_dev_update_int_value(kk_map_dev_node_t *node,char *identifier,int val)
{ {
int ret = 0; int ret = 0;
if(node != NULL && node->newccu != NULL){ if(node != NULL && node->newccu != NULL){
cJSON * newccuItem = node->newccu->child; cJSON * newccuItem = node->newccu->child;
while(newccuItem != NULL){ while(newccuItem != NULL){
char *identifier_tmp = cJSON_GetObjectItem(newccuItem,MSG_INDENTIFIER_STR)->valuestring; char *identifier_tmp = cJSON_GetObjectItem(newccuItem,MSG_INDENTIFIER_STR)->valuestring;
if(strcmp(identifier_tmp,identifier) == 0){ if(strcmp(identifier_tmp,identifier) == 0){
cJSON_ReplaceItemInObject(newccuItem, "value", cJSON_CreateNumber(val)); cJSON_ReplaceItemInObject(newccuItem, "value", cJSON_CreateNumber(val));
break; break;
} }
newccuItem = newccuItem->next; newccuItem = newccuItem->next;
} }
} }
return 0; return 0;
} }
int kk_map_dev_update_int_value_by_devicecode(char *deviceCode,char *identifier,int val) int kk_map_dev_update_int_value_by_devicecode(char *deviceCode,char *identifier,int val)
{ {
...@@ -291,6 +421,7 @@ int kk_map_dev_update_int_value_by_devicecode(char *deviceCode,char *identifier, ...@@ -291,6 +421,7 @@ int kk_map_dev_update_int_value_by_devicecode(char *deviceCode,char *identifier,
return 0; return 0;
} }
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 *ctx = _kk_map_dev_ctx(); kk_map_dev_ctx *ctx = _kk_map_dev_ctx();
...@@ -307,33 +438,101 @@ int kk_map_dev_search_by_deviceCode(char *deviceCode, kk_map_dev_node_t **node) ...@@ -307,33 +438,101 @@ int kk_map_dev_search_by_deviceCode(char *deviceCode, kk_map_dev_node_t **node)
} }
} }
ERROR_PRINT("Device Not Found, deviceCode: %s", deviceCode); ERROR_PRINT("Device Not Found, deviceCode: %s\n", deviceCode);
return -1; return -1;
} }
kk_map_dev_node_t *kk_map_dev_add(char *deviceCode,char *productCode,char *gwdeviceCode)
kk_map_dev_node_t *kk_map_dev_add(char *deviceCode,char *productCode,char *gwdeviceCode,char *onlineStatus)
{ {
#if 1 #if 1
kk_map_dev_node_t *node = NULL; kk_map_dev_node_t *node = NULL;
kk_map_dev_ctx *ctx = _kk_map_dev_ctx(); kk_map_dev_ctx *ctx = _kk_map_dev_ctx();
node = malloc(sizeof(kk_map_dev_node_t));
if (node == NULL) {
return NULL;
}
printf("----------------------------------------->%s\n",onlineStatus);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
_kk_map_dev_mutex_lock();
printf("[%s][%d]%d\n",__FUNCTION__,__LINE__,onlineStatus);
memset(node,0x0,sizeof(kk_map_dev_node_t));
printf("[%s][%d]%d\n",__FUNCTION__,__LINE__,onlineStatus);
memcpy(node->gwDeviceCode,gwdeviceCode,strlen(gwdeviceCode));
printf("[%s][%d]%d\n",__FUNCTION__,__LINE__,onlineStatus);
memcpy(node->deviceCode,deviceCode,strlen(deviceCode));
printf("[%s][%d]%d\n",__FUNCTION__,__LINE__,onlineStatus);
memcpy(node->productCode,productCode,strlen(productCode));
printf("[%s][%d]%d\n",__FUNCTION__,__LINE__,onlineStatus);
if(onlineStatus){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
printf("[%s][%d]%d\n",__FUNCTION__,__LINE__,onlineStatus);
}else{
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if(strcmp(onlineStatus,"1")==0){
node->online_status=1;
}else{
node->online_status=0;
}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_open_cfg_file(productCode,node);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
INIT_LIST_HEAD(&node->linked_list);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
printf("#55,%d\n",node);
list_add_tail(&node->linked_list, &ctx->dev_list);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
_kk_map_dev_mutex_unlock();
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return node;
#endif
}
/*
int get_productCode_by_deviceCode(const char *deviceCode)
{
kk_map_dev_ctx *ctx = _kk_map_dev_ctx();
kk_map_dev_node_t *search_node = NULL;
list_for_each_entry(search_node, &ctx->dev_list, linked_list, kk_map_dev_node_t) {
if ( (strlen(search_node->deviceCode) == strlen(deviceCode)) &&
(memcmp(search_node->deviceCode, deviceCode, strlen(deviceCode)) == 0)) {
item = kk_zb_dev_hw_info_build(search_node->deviceCode,search_node->productCode,search_node->online_status,NULL,NULL);
return item;
}
}
return NULL;
}
*/
node = malloc(sizeof(kk_map_dev_node_t));
if (node == NULL) {
return NULL;
}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
_kk_map_dev_mutex_lock();
memset(node,0x0,sizeof(kk_map_dev_node_t));
memcpy(node->gwDeviceCode,gwdeviceCode,strlen(gwdeviceCode));
memcpy(node->deviceCode,deviceCode,strlen(deviceCode));
memcpy(node->productCode,productCode,strlen(productCode));
kk_open_cfg_file(productCode,node);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
INIT_LIST_HEAD(&node->linked_list);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
list_add_tail(&node->linked_list, &ctx->dev_list);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
_kk_map_dev_mutex_unlock();
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return node;
#endif
}
\ No newline at end of file
...@@ -8,22 +8,32 @@ ...@@ -8,22 +8,32 @@
#include "com_api.h" #include "com_api.h"
#include "kk_opcode.h" #include "kk_opcode.h"
typedef struct { typedef struct {
cJSON *newccu; cJSON *json;
cJSON *oldccu; cJSON *newccu;
int channelNum; cJSON *oldccu;
char gwDeviceCode[DEVICE_CODE_LEN]; unsigned char online_status;
char productCode[PRODUCT_CODE_LEN]; int channelNum;
char deviceCode[DEVICE_CODE_LEN]; int syn_type;
char opearteType[8]; char *syn_opcode;
struct list_head linked_list; char gwDeviceCode[DEVICE_CODE_LEN];
char productCode[PRODUCT_CODE_LEN];
char deviceCode[DEVICE_CODE_LEN];
char opearteType[8];
struct list_head linked_list;
} kk_map_dev_node_t; } kk_map_dev_node_t;
typedef struct { typedef struct {
void *mutex; void *mutex;
struct list_head dev_list; struct list_head dev_list;
} kk_map_dev_ctx; } kk_map_dev_ctx;
kk_map_dev_node_t *kk_map_dev_add(char *deviceCode,char *productCode,char *gwdeviceCode); kk_map_dev_node_t *kk_map_dev_add(char *deviceCode,char *productCode,char *gwdeviceCode,char *onlineStatus);
int kk_create_devicestatus_to_sdk(cJSON *root); int kk_create_devicestatus_to_sdk(cJSON *root);
int kk_create_devices_to_sdk(cJSON *root); int kk_create_devices_to_sdk(cJSON *root);
int _deviceCode_switchto_mac(char * deviceCode,char *mac);
int mac_switchto_deviceCode(char *mac,char * deviceCode);
kk_map_dev_ctx *_kk_map_dev_ctx(void);
#endif #endif
\ No newline at end of file
...@@ -18,46 +18,46 @@ ...@@ -18,46 +18,46 @@
#include "cJSON.h" #include "cJSON.h"
static int kk_findccu_ack(int sockfd,struct sockaddr_in *addr){ static int kk_findccu_ack(int sockfd,struct sockaddr_in *addr){
cJSON *json = NULL,*args = NULL; cJSON *json = NULL,*args = NULL;
cJSON *ccu = NULL; cJSON *ccu = NULL;
char *out = NULL; char *out = NULL;
char *tmpBuf = NULL; char *tmpBuf = NULL;
char s_IP[NETWORK_ADDR_LEN] = {0}; char s_IP[NETWORK_ADDR_LEN] = {0};
if(addr == NULL || sockfd < 0){ if(addr == NULL || sockfd < 0){
return -1; return -1;
} }
json=cJSON_CreateObject(); json=cJSON_CreateObject();
if(json){ if(json){
args = cJSON_CreateObject(); args = cJSON_CreateObject();
if(args){ if(args){
cJSON_AddItemToObject(json, "arg", args); cJSON_AddItemToObject(json, "arg", args);
cJSON_AddStringToObject(args, "zkid", KK_CCU_ID); cJSON_AddStringToObject(args, "zkid", KK_CCU_ID);
cJSON_AddStringToObject(args, "zk", KK_CCU_NAME); cJSON_AddStringToObject(args, "zk", KK_CCU_NAME);
HAL_Get_IP(s_IP,NULL); HAL_Get_IP(s_IP,NULL);
cJSON_AddStringToObject(args, "ip", s_IP); cJSON_AddStringToObject(args, "ip", s_IP);
cJSON_AddBoolToObject(args, "ssl", FALSE); cJSON_AddBoolToObject(args, "ssl", FALSE);
} }
cJSON_AddStringToObject(json, "nodeid", "*"); cJSON_AddStringToObject(json, "nodeid", "*");
cJSON_AddStringToObject(json, "opcode", FINDCCU_OPCODE); cJSON_AddStringToObject(json, "opcode", FINDCCU_OPCODE);
cJSON_AddStringToObject(json, "status", "success"); cJSON_AddStringToObject(json, "status", "success");
out=cJSON_Print(json); out=cJSON_Print(json);
cJSON_Minify((char*)out); cJSON_Minify((char*)out);
tmpBuf = calloc(strlen(out) + 4,1); tmpBuf = calloc(strlen(out) + 4,1);
if(tmpBuf == NULL){ if(tmpBuf == NULL){
cJSON_Delete(json); cJSON_Delete(json);
free(out); free(out);
return -1; return -1;
} }
strcat(tmpBuf,"!"); strcat(tmpBuf,"!");
strcat(tmpBuf,out); strcat(tmpBuf,out);
strcat(tmpBuf,"$"); strcat(tmpBuf,"$");
printf("tmpBuf:%s\n",tmpBuf); printf("tmpBuf:%s\n",tmpBuf);
sendto(sockfd, tmpBuf, strlen(tmpBuf), 0, (struct sockaddr*)addr, sizeof(struct sockaddr_in)); sendto(sockfd, tmpBuf, strlen(tmpBuf), 0, (struct sockaddr*)addr, sizeof(struct sockaddr_in));
cJSON_Delete(json); cJSON_Delete(json);
free(out); free(out);
free(tmpBuf); free(tmpBuf);
} }
return 0; return 0;
} }
void *kk_findccu_handle(void *data) void *kk_findccu_handle(void *data)
{ {
...@@ -65,73 +65,73 @@ void *kk_findccu_handle(void *data) ...@@ -65,73 +65,73 @@ void *kk_findccu_handle(void *data)
struct sockaddr_in saddr; struct sockaddr_in saddr;
int r; int r;
char recvline[1025] = {0}; char recvline[1025] = {0};
char recvline_tmp[1025] = {0}; char recvline_tmp[1025] = {0};
struct sockaddr_in presaddr; struct sockaddr_in presaddr;
socklen_t len; socklen_t len;
cJSON *json; cJSON *json;
cJSON *opcode; cJSON *opcode;
char *pStart = NULL,*pEnd = NULL; char *pStart = NULL,*pEnd = NULL;
sockfd = socket(AF_INET, SOCK_DGRAM, 0); sockfd = socket(AF_INET, SOCK_DGRAM, 0);
bzero(&saddr, sizeof(saddr)); bzero(&saddr, sizeof(saddr));
saddr.sin_family = AF_INET; saddr.sin_family = AF_INET;
saddr.sin_addr.s_addr = htonl(INADDR_ANY); saddr.sin_addr.s_addr = htonl(INADDR_ANY);
saddr.sin_port = htons(FINDCCU_LOCAL_PORT); saddr.sin_port = htons(FINDCCU_LOCAL_PORT);
if(bind(sockfd, (struct sockaddr*)&saddr, sizeof(saddr)) == -1) if(bind(sockfd, (struct sockaddr*)&saddr, sizeof(saddr)) == -1)
{ {
ERROR_PRINT("bind error...\n"); ERROR_PRINT("bind error...\n");
} }
while (1) while (1)
{ {
r = recvfrom(sockfd, recvline, sizeof(recvline), 0 , (struct sockaddr*)&presaddr, &len); r = recvfrom(sockfd, recvline, sizeof(recvline), 0 , (struct sockaddr*)&presaddr, &len);
if (r <= 0){ if (r <= 0){
WARNING_PRINT("read error....\n"); WARNING_PRINT("read error....\n");
}else{ }else{
DEBUG_PRINT("findccu recmsg: %s\n", recvline); DEBUG_PRINT("findccu recmsg: %s\n", recvline);
pStart = strstr(recvline, "!"); pStart = strstr(recvline, "!");
pEnd = strstr(recvline, "$"); pEnd = strstr(recvline, "$");
if(pStart != NULL && pEnd != NULL){ if(pStart != NULL && pEnd != NULL){
memset(recvline_tmp,0x0,sizeof(recvline_tmp)); memset(recvline_tmp,0x0,sizeof(recvline_tmp));
memcpy(recvline_tmp,pStart+1,(pEnd - pStart - 1)); memcpy(recvline_tmp,pStart+1,(pEnd - pStart - 1));
json=cJSON_Parse(recvline_tmp); json=cJSON_Parse(recvline_tmp);
if (!json) { if (!json) {
WARNING_PRINT("Error before: [%s]\n","cJSON_Parse"); WARNING_PRINT("Error before: [%s]\n","cJSON_Parse");
}else{ }else{
opcode = cJSON_GetObjectItem(json, OPCODE_STRING); opcode = cJSON_GetObjectItem(json, OPCODE_STRING);
if(opcode != NULL){ if(opcode != NULL){
if(strcmp(opcode->valuestring,FINDCCU_OPCODE) == 0){ if(strcmp(opcode->valuestring,FINDCCU_OPCODE) == 0){
kk_findccu_ack(sockfd,&presaddr); kk_findccu_ack(sockfd,&presaddr);
} }
} }
cJSON_Delete(json); cJSON_Delete(json);
} }
}else{ }else{
WARNING_PRINT("data error....\n"); WARNING_PRINT("data error....\n");
} }
} }
} }
return NULL; return NULL;
} }
int kk_findccu_handle_init(void) int kk_findccu_handle_init(void)
{ {
int rc = 0; int rc = 0;
size_t s = 1500; size_t s = 1500;
pthread_t findccu_thread_handle; pthread_t findccu_thread_handle;
pthread_attr_t findccu_thread_attr; pthread_attr_t findccu_thread_attr;
//pthread_mutex_init(&s_data_mutex, NULL); //pthread_mutex_init(&s_data_mutex, NULL);
/*创建线程*/ /*创建线程*/
pthread_attr_init(&findccu_thread_attr); pthread_attr_init(&findccu_thread_attr);
pthread_attr_setstacksize(&findccu_thread_attr, s); pthread_attr_setstacksize(&findccu_thread_attr, s);
pthread_attr_setdetachstate(&findccu_thread_attr, PTHREAD_CREATE_DETACHED); pthread_attr_setdetachstate(&findccu_thread_attr, PTHREAD_CREATE_DETACHED);
rc = pthread_create(&findccu_thread_handle, &findccu_thread_attr, kk_findccu_handle, (void *)NULL); //收数据 rc = pthread_create(&findccu_thread_handle, &findccu_thread_attr, kk_findccu_handle, (void *)NULL); //收数据
if (rc) if (rc)
{ {
WARNING_PRINT("Error : unable to create thread udp_recv \r\n"); WARNING_PRINT("Error : unable to create thread udp_recv \r\n");
return -1; return -1;
} }
pthread_attr_destroy(&findccu_thread_attr); pthread_attr_destroy(&findccu_thread_attr);
return 0; return 0;
} }
\ No newline at end of file
...@@ -24,18 +24,40 @@ ...@@ -24,18 +24,40 @@
#include "kk_findccu_handle.h" #include "kk_findccu_handle.h"
#include "kk_login_handle.h" #include "kk_login_handle.h"
#include "kk_data_handle.h" #include "kk_data_handle.h"
//#include "kcloud_log.h"
//#include "kk_lan_queue.h"
#include "kk_lan_node_db.h"
static void sig_handler(int sig)
{
printf("Received signal: %d\n", sig);
abort();
}
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
int rc = 0; int rc = 0;
char *ppp;
open("kk_lan",LOG_PID,LOG_USER); open("kk_lan",LOG_PID,LOG_USER);
/*set the callback to get the device date to cloud*/ /*set the callback to get the device date to cloud*/
kk_ipc_init(IPC_APP2MID,(ipc_cb*)KK_Data_FromMid,NULL,NULL); kk_ipc_init(IPC_APP2MID,(ipc_cb*)KK_Data_FromMid,NULL,NULL);
kk_findccu_handle_init(); kk_findccu_handle_init();
kk_map_dev_init(); kk_map_dev_init();
kk_login_init(); kk_login_init();
struct sigaction sig = {0};
sig.sa_handler = sig_handler;
sig.sa_flags = 0;
for(int i=0;i<31;i++){
//sigaction(i, &sig, NULL);
}
//lan_queue_init();
kk_lan_db_node_init();
kk_handle_sync_info();
while(1){ while(1){
//count++; //count++;
//if(count == 10){ //if(count == 10){
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
#define BUF_SIZE 1500 #define BUF_SIZE 1500
typedef struct { typedef struct {
int socketfd; int socketfd;
char ip[18]; char ip[18];
} kk_clientInfo_t; } kk_clientInfo_t;
static kk_clientInfo_t s_ConnInfo[LISTEN_MAX] = {0}; static kk_clientInfo_t s_ConnInfo[LISTEN_MAX] = {0};
static pthread_mutex_t data_mutex; static pthread_mutex_t data_mutex;
...@@ -27,47 +27,50 @@ fd_set fds; ...@@ -27,47 +27,50 @@ fd_set fds;
int kk_send_data_to_sdk(char *buf) int kk_send_data_to_sdk(char *buf)
{ {
char *tmpBuf = NULL; char *tmpBuf = NULL;
int i = 0; int i = 0;
tmpBuf = calloc(strlen(buf) + 4,1); tmpBuf = calloc(strlen(buf) + 4,1);
if(tmpBuf == NULL){ if(tmpBuf == NULL){
return -1; return -1;
} }
strcat(tmpBuf,"!"); strcat(tmpBuf,"!");
strcat(tmpBuf,buf); strcat(tmpBuf,buf);
strcat(tmpBuf,"$"); strcat(tmpBuf,"$");
printf("tmpBuf:%s\n",tmpBuf); printf("tmpBuf:%s\n",tmpBuf);
for(i = 0; i < LISTEN_MAX; i++){ for(i = 0; i < LISTEN_MAX; i++){
if(s_ConnInfo[i].socketfd != -1){ if(s_ConnInfo[i].socketfd != -1){
send(s_ConnInfo[i].socketfd, tmpBuf, strlen(tmpBuf), 0); send(s_ConnInfo[i].socketfd, tmpBuf, strlen(tmpBuf), 0);
} }
} }
free(buf);
free(tmpBuf); free(tmpBuf);
return 0; return 0;
} }
static int _kk_handle_data(char *buf,int sockfd){ static int _kk_handle_data(char *buf,int sockfd){
char *pStart = NULL,*pEnd = NULL; char *pStart = NULL,*pEnd = NULL;
char tmpBuf[BUF_SIZE] = {0}; char tmpBuf[BUF_SIZE] = {0};
cJSON *json; cJSON *json;
if(buf == NULL){ if(buf == NULL){
return -1; return -1;
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__); 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));
} }
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");
}else{ }else{
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_data_handle(json,sockfd); kk_data_handle(json,sockfd);
cJSON_Delete(json);
} printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON_Delete(json);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
}
} }
static void PrintMesg(int i , char buf[]) static void PrintMesg(int i , char buf[])
...@@ -77,198 +80,200 @@ static void PrintMesg(int i , char buf[]) ...@@ -77,198 +80,200 @@ static void PrintMesg(int i , char buf[])
void *TCP_Analyzer(void *pPara) void *TCP_Analyzer(void *pPara)
{ {
char Buf[BUF_SIZE] = {0}; char Buf[BUF_SIZE] = {0};
ssize_t Size = 0; ssize_t Size = 0;
int index = 0; int index = 0;
unsigned char *pReceiveData = NULL; unsigned char *pReceiveData = NULL;
int ReceiveLen = 0; int ReceiveLen = 0;
if (NULL == pPara)
{
ERROR_PRINT("TCP_Analyzer: TCP_Analyzer Failed!\n");
return NULL;
}
if (NULL == pPara) index = *(int *)pPara;
{ printf("index:%d\n",*(int *)pPara);
ERROR_PRINT("TCP_Analyzer: TCP_Analyzer Failed!\n"); if(index < 0 || index >= LISTEN_MAX)
return NULL; {
} ERROR_PRINT("TCP_Analyzer:Get pConnfd Failed \n" );
return NULL;
}
index = *(int *)pPara; while(1)
printf("index:%d\n",*(int *)pPara); {
if(index < 0 || index >= LISTEN_MAX) memset(Buf, '\0', sizeof(Buf));
{ Size = read(s_ConnInfo[index].socketfd, Buf,sizeof(Buf) );
ERROR_PRINT("TCP_Analyzer:Get pConnfd Failed \n" ); if (Size <= 0) //没有接收到数据,关闭描述符,释放在TCPServer申请的空间
return NULL; {
} ERROR_PRINT("TCP_Analyzer:remote client close:%d\n",s_ConnInfo[index].socketfd );
pthread_mutex_lock(&data_mutex);
close(s_ConnInfo[index].socketfd);
s_ConnInfo[index].socketfd = -1;
memset(s_ConnInfo[index].ip,0x0,sizeof(s_ConnInfo[index].ip));
pthread_mutex_unlock(&data_mutex);
while(1) return NULL;
{ }
memset(Buf, '\0', sizeof(Buf)); else
Size = read(s_ConnInfo[index].socketfd, Buf,sizeof(Buf) ); {
if (Size <= 0) //没有接收到数据,关闭描述符,释放在TCPServer申请的空间 printf("TCP_Analyzer:%s,%d\n",Buf,(int)Size);
{ _kk_handle_data(Buf,s_ConnInfo[index].socketfd);
ERROR_PRINT("TCP_Analyzer:remote client close:%d\n",s_ConnInfo[index].socketfd ); printf("[%s][%d] TCP_Analyzer end.\n",__FUNCTION__,__LINE__);
pthread_mutex_lock(&data_mutex); }
close(s_ConnInfo[index].socketfd); }
s_ConnInfo[index].socketfd = -1; return NULL;
memset(s_ConnInfo[index].ip,0x0,sizeof(s_ConnInfo[index].ip));
pthread_mutex_unlock(&data_mutex);
return NULL;
}
else
{
printf("TCP_Analyzer:%s,%d\n",Buf,(int)Size);
_kk_handle_data(Buf,s_ConnInfo[index].socketfd);
}
}
return NULL;
} }
static int kk_check_is_connect(char *ip){ static int kk_check_is_connect(char *ip){
int i = 0; int i = 0;
if(ip == NULL){ if(ip == NULL){
return -1; return -1;
} }
for(i = 0; i < LISTEN_MAX; i ++){ for(i = 0; i < LISTEN_MAX; i ++){
if(s_ConnInfo[i].socketfd != -1 && strcmp(s_ConnInfo[i].ip,ip) == 0){ if(s_ConnInfo[i].socketfd != -1 && strcmp(s_ConnInfo[i].ip,ip) == 0){
return 1; return 1;
} }
} }
return 0; return 0;
} }
void *TCPServer() void *TCPServer()
{ {
pthread_t threadID = 0; pthread_t threadID = 0;
struct sockaddr_in Server; struct sockaddr_in Server;
struct sockaddr_in Client; struct sockaddr_in Client;
int Listenfd = 0; int Listenfd = 0;
int i = 0; int i = 0;
int j = 0; int j = 0;
int yes = 1; int yes = 1;
int index = 0; int index = 0;
int Connfd = 0; int Connfd = 0;
int ret = 0; int ret = 0;
char clientIp[18] = {0}; char clientIp[18] = {0};
socklen_t len = 0; socklen_t len = 0;
//char logMessage[128] = {0}; //char logMessage[128] = {0};
pthread_attr_t attr; pthread_attr_t attr;
pthread_attr_init(&attr); pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Listenfd = socket(AF_INET, SOCK_STREAM, 0);
if (Listenfd < 0)
{
perror("socket");
pthread_attr_destroy(&attr);//线程属性销毁
return NULL;
}
DEBUG_PRINT("TCPServer:create socket success\n");
setsockopt(Listenfd, SOL_SOCKET, SO_REUSEADDR, &yes ,sizeof(int));// 允许IP地址复用
bzero(&Server, sizeof(Server));
Server.sin_family = AF_INET;
Server.sin_port = htons(SERVER_LISTEN_PORT);
Server.sin_addr.s_addr = htonl(INADDR_ANY);
Listenfd = socket(AF_INET, SOCK_STREAM, 0); if (bind(Listenfd, (struct sockaddr*)&Server, sizeof(Server)) < 0)
if (Listenfd < 0) {
{ perror("bind");
perror("socket"); close(Listenfd);
pthread_attr_destroy(&attr);//线程属性销毁 pthread_attr_destroy(&attr);//线程属性销毁
return NULL; return NULL;
} }
DEBUG_PRINT("TCPServer:create socket success\n"); DEBUG_PRINT("TCPServer:bind socket success\n");
setsockopt(Listenfd, SOL_SOCKET, SO_REUSEADDR, &yes ,sizeof(int));// 允许IP地址复用
bzero(&Server, sizeof(Server));
Server.sin_family = AF_INET;
Server.sin_port = htons(SERVER_LISTEN_PORT);
Server.sin_addr.s_addr = htonl(INADDR_ANY);
if (bind(Listenfd, (struct sockaddr*)&Server, sizeof(Server)) < 0) if (listen(Listenfd, LISTEN_MAX) < 0)
{ {
perror("bind"); perror("listen");
close(Listenfd); close(Listenfd);
pthread_attr_destroy(&attr);//线程属性销毁 pthread_attr_destroy(&attr);//线程属性销毁
return NULL; return NULL;
} }
DEBUG_PRINT("TCPServer:bind socket success\n"); DEBUG_PRINT("TCPServer:listen socket success\n");
if (listen(Listenfd, LISTEN_MAX) < 0) while (1)
{ {
perror("listen"); //index = -1;
close(Listenfd); FD_ZERO(&fds);//描述符集合初始化
pthread_attr_destroy(&attr);//线程属性销毁
return NULL;
}
DEBUG_PRINT("TCPServer:listen socket success\n");
while (1) FD_SET(Listenfd,&fds);
{ struct timeval timeout = {1, 0};
//index = -1; ret = select(Listenfd + 1, &fds,NULL, NULL, &timeout );
FD_ZERO(&fds);//描述符集合初始化 if(ret <= 0){
DEBUG_PRINT("TCPServer:TCP receiving nothing......\n");
FD_SET(Listenfd,&fds); //break;
struct timeval timeout = {1, 0}; }else{
ret = select(Listenfd + 1, &fds,NULL, NULL, &timeout ); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if(ret <= 0){ if (FD_ISSET(Listenfd, &fds))
DEBUG_PRINT("TCPServer:TCP receiving nothing......\n"); {
//break; len = sizeof(Client);
}else{ bzero(&Client, len);
printf("[%s][%d]\n",__FUNCTION__,__LINE__); Connfd = accept(Listenfd, (struct sockaddr*)&Client,&len );
if (FD_ISSET(Listenfd, &fds)) printf("addr:%s\n",inet_ntoa(Client.sin_addr));
{ printf("[%s][%d]Connfd:%d\n",__FUNCTION__,__LINE__,Connfd);
len = sizeof(Client); //若有新的连接
bzero(&Client, len); if (Connfd != -1)
Connfd = accept(Listenfd, (struct sockaddr*)&Client,&len ); {
printf("addr:%s\n",inet_ntoa(Client.sin_addr)); memset(clientIp,0x0,sizeof(clientIp));
printf("[%s][%d]Connfd:%d\n",__FUNCTION__,__LINE__,Connfd); strcpy(clientIp,inet_ntoa(Client.sin_addr));
//若有新的连接 if(kk_check_is_connect(clientIp) == 1){
if (Connfd != -1) DEBUG_PRINT("already connect!!!\n");
{ continue;
memset(clientIp,0x0,sizeof(clientIp)); }
strcpy(clientIp,inet_ntoa(Client.sin_addr)); for(i = 0; i < LISTEN_MAX; i ++){
if(kk_check_is_connect(clientIp) == 1){ if(s_ConnInfo[i].socketfd != -1){
DEBUG_PRINT("already connect!!!\n"); if(i == LISTEN_MAX-1){
continue; DEBUG_PRINT("more then max client!!!\n");
} }
for(i = 0; i < LISTEN_MAX; i ++){ continue;
if(s_ConnInfo[i].socketfd != -1){ }else{
if(i == 4){ pthread_mutex_lock(&data_mutex);
DEBUG_PRINT("more then max client!!!\n"); s_ConnInfo[i].socketfd = Connfd;
} memcpy(s_ConnInfo[i].ip,clientIp,strlen(clientIp));
continue; index = i;
}else{ printf("index:%d\n",index);
pthread_mutex_lock(&data_mutex); pthread_mutex_unlock(&data_mutex);
s_ConnInfo[i].socketfd = Connfd; break;
memcpy(s_ConnInfo[i].ip,clientIp,strlen(clientIp)); }
index = i; }
printf("index:%d\n",index); ret = pthread_create(&threadID, &attr, TCP_Analyzer, &index);
pthread_mutex_unlock(&data_mutex); if(0 != ret)
break; {
} DEBUG_PRINT("TCPServer: TCP_Analyzer build Fail!\n");
} FD_CLR(Listenfd, &fds);// 清除 fds中相应的文件描述符
ret = pthread_create(&threadID, &attr, TCP_Analyzer, &index); close(Listenfd);
if(0 != ret) pthread_attr_destroy(&attr);//线程属性销毁
{ return NULL;
DEBUG_PRINT("TCPServer: TCP_Analyzer build Fail!\n"); }
FD_CLR(Listenfd, &fds);// 清除 fds中相应的文件描述符
close(Listenfd);
pthread_attr_destroy(&attr);//线程属性销毁
return NULL;
}
} }
} }
} }
} }
FD_CLR(Listenfd, &fds);// 清除 fds中相应的文件描述符 FD_CLR(Listenfd, &fds);// 清除 fds中相应的文件描述符
close(Listenfd); close(Listenfd);
pthread_attr_destroy(&attr);//线程属性销毁 pthread_attr_destroy(&attr);//线程属性销毁
return NULL; return NULL;
} }
int kk_login_init() int kk_login_init()
{ {
int ret = 0; int ret = 0;
int i = 0; int i = 0;
pthread_t threadID = 0; pthread_t threadID = 0;
DEBUG_PRINT("kk_login_init Init OK!\n"); DEBUG_PRINT("kk_login_init Init OK!\n");
for(i = 0; i < LISTEN_MAX; i ++){ for(i = 0; i < LISTEN_MAX; i ++){
s_ConnInfo[i].socketfd = -1; s_ConnInfo[i].socketfd = -1;
memset(s_ConnInfo[i].ip,0x0,sizeof(s_ConnInfo[i].ip)); memset(s_ConnInfo[i].ip,0x0,sizeof(s_ConnInfo[i].ip));
} }
if (pthread_mutex_init(&data_mutex, NULL) != 0) { if (pthread_mutex_init(&data_mutex, NULL) != 0) {
ERROR_PRINT("pthread_mutex_init kk_login_init err\n"); ERROR_PRINT("pthread_mutex_init kk_login_init err\n");
return -1; return -1;
} }
ret = pthread_create(&threadID, NULL, TCPServer, NULL); ret = pthread_create(&threadID, NULL, TCPServer, NULL);
if(0 != ret) if(0 != ret)
{ {
ERROR_PRINT("TCPServer: TCPServer build Fail!\n"); ERROR_PRINT("TCPServer: TCPServer build Fail!\n");
return -1; return -1;
} }
return 0; return 0;
} }
...@@ -16,10 +16,21 @@ ...@@ -16,10 +16,21 @@
#define OPEARTETYPE_STRING "operateType" #define OPEARTETYPE_STRING "operateType"
#define NEWCCU_STRING "newccu" #define NEWCCU_STRING "newccu"
#define OLDCCU_STRING "oldccu" #define OLDCCU_STRING "oldccu"
#define FINDCCU_OPCODE "FIND_CCU" #define FINDCCU_OPCODE "FIND_CCU"
#define LOGIN_OPCODE "LOGIN" #define LOGIN_OPCODE "LOGIN"
#define HEARTBEAT_OPCODE "CCU_HB" #define HEARTBEAT_OPCODE "CCU_HB"
#define SYNC_OPCODE "SYNC_INFO" #define SYNC_OPCODE "SYNC_INFO"
#define GET_ZB_DEVS_HW_INFO_OPCODE "GET_ZIGBEE_DEVS_HW_INFO"
#define SWITCH_OPCODE "SWITCH"
#define VALUERANGE_STRING "valueRange" #define VALUERANGE_STRING "valueRange"
#define DEVICE_FIELD_STRING "device_field" #define DEVICE_FIELD_STRING "device_field"
#define DEVICE_FIELD_IDNDEX_STRING "device_field_index" #define DEVICE_FIELD_IDNDEX_STRING "device_field_index"
...@@ -31,4 +42,4 @@ ...@@ -31,4 +42,4 @@
#define OPERATE_TYPE_STRING "operate_type" #define OPERATE_TYPE_STRING "operate_type"
#define ROOM_ID_STRING "room_id" #define ROOM_ID_STRING "room_id"
#define DEVICE_STATUS_STRING "device_status" #define DEVICE_STATUS_STRING "device_status"
#endif #endif
\ No newline at end of file
...@@ -6,8 +6,11 @@ ...@@ -6,8 +6,11 @@
#define APP2MID "ipc:///tmp/app2mid.ipc" #define APP2MID "ipc:///tmp/app2mid.ipc"
#define APP2MID_PUBSUB "ipc:///tmp/app2mid_pubsub.ipc" #define APP2MID_PUBSUB "ipc:///tmp/app2mid_pubsub.ipc"
#define PLAT2MID "ipc:///tmp/plat2mid.ipc" #define PLAT2MID "ipc:///tmp/plat2mid.ipc"
//#define GW2CCU_PIPE "tcp://%s:5555"
//#define GW2CCU_PUBSUB "tcp://%s:5557"
#define GW2CCU_PIPE "tcp://%s:35567" #define GW2CCU_PIPE "tcp://%s:35567"
#define GW2CCU_PUBSUB "tcp://%s:35568" #define GW2CCU_PUBSUB "tcp://%s:35568"
#define MAGIC "magic12" #define MAGIC "magic12"
#define MAGIC_ACK "magic12ack" #define MAGIC_ACK "magic12ack"
#define FILTERSTR "|" #define FILTERSTR "|"
......
...@@ -38,6 +38,11 @@ typedef enum { ...@@ -38,6 +38,11 @@ typedef enum {
#define MSG_PAYLOAD_STR "payload" #define MSG_PAYLOAD_STR "payload"
#define MSG_INFO_STR "info" #define MSG_INFO_STR "info"
#define MSG_INDENTIFIER_STR "identifier" #define MSG_INDENTIFIER_STR "identifier"
#define MSG_DATA_TYPE_STR "dataType"
#define MSG_PARAMS_STR "params" #define MSG_PARAMS_STR "params"
#define MSG_IOTClOUDSTATE_STR "IOTCloudState" #define MSG_IOTClOUDSTATE_STR "IOTCloudState"
#define MSG_TOPO_CHANGE_TYPE_STR "changeType" #define MSG_TOPO_CHANGE_TYPE_STR "changeType"
...@@ -64,6 +69,8 @@ typedef enum { ...@@ -64,6 +69,8 @@ typedef enum {
#define MSG_TIMER_SETCOUNTDOWN_GETCOUNTDOWN "getCountDown" #define MSG_TIMER_SETCOUNTDOWN_GETCOUNTDOWN "getCountDown"
#define MSG_PROPERTY_STR "property" #define MSG_PROPERTY_STR "property"
#define MSG_PROPERTIES_STR "properties" #define MSG_PROPERTIES_STR "properties"
#define MSG_ONLINE_STATUS_STR "onlineStatus"
/************************LOCK KEY*************************/ /************************LOCK KEY*************************/
#define MSG_KEYDELETE_NOTIFICATION_KEYID "KeyDeletedNotification.KeyID" #define MSG_KEYDELETE_NOTIFICATION_KEYID "KeyDeletedNotification.KeyID"
#define MSG_KEYDELETE_NOTIFICATION_KEYTYPE "KeyDeletedNotification.KeyType" #define MSG_KEYDELETE_NOTIFICATION_KEYTYPE "KeyDeletedNotification.KeyType"
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#define PRODUCT_TPYE "kk" #define PRODUCT_TPYE "kk"
#define CCU_LAN "eth1" #define CCU_LAN "eth1"
#define KK_CCU_ID "CCU_77777" #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"
#define KK_CCU_RANDOM "0000000000" #define KK_CCU_RANDOM "0000000000"
......
...@@ -13,7 +13,7 @@ COMP_LIB_COMPONENTS := \ ...@@ -13,7 +13,7 @@ COMP_LIB_COMPONENTS := \
#SUBDIRS += application/kcloud #SUBDIRS += application/kcloud
$(call Append_Conditional, SUBDIRS, application/kcloud, KCLOUD_PLATFORM_SUPPORT) $(call Append_Conditional, SUBDIRS, application/kcloud, KCLOUD_PLATFORM_SUPPORT)
$(call Append_Conditional, SUBDIRS, application/kk_luoma, LUOMA_PLATFORM_SUPPORT) $(call Append_Conditional, SUBDIRS, application/kk_luoma, LUOMA_PLATFORM_SUPPORT)
SUBDIRS += application/oled #SUBDIRS += application/oled
SUBDIRS += application/klansdk SUBDIRS += application/klansdk
SUBDIRS += midware/midware SUBDIRS += midware/midware
SUBDIRS += common/mqtt SUBDIRS += common/mqtt
......
...@@ -154,6 +154,8 @@ static int kk_get_properties_info(char *deviceCode,cJSON *obj) ...@@ -154,6 +154,8 @@ static int kk_get_properties_info(char *deviceCode,cJSON *obj)
valueType == KK_TSL_DATA_TYPE_ENUM|| valueType == KK_TSL_DATA_TYPE_ENUM||
valueType == KK_TSL_DATA_TYPE_BOOL){ valueType == KK_TSL_DATA_TYPE_BOOL){
cJSON_AddNumberToObject(propertyItem, propertyStr, atoi(valueStr)); cJSON_AddNumberToObject(propertyItem, propertyStr, atoi(valueStr));
}else if(valueType == KK_TSL_DATA_TYPE_DOUBLE){
cJSON_AddNumberToObject(propertyItem, propertyStr, atof(valueStr));
} }
} }
cJSON_AddItemToObject(obj, KK_SYNC_PROPERTY_STR, propertyItem); cJSON_AddItemToObject(obj, KK_SYNC_PROPERTY_STR, propertyItem);
......
...@@ -139,29 +139,29 @@ int kk_utils_itoa(_IN_ int input, _OU_ char **output) ...@@ -139,29 +139,29 @@ int kk_utils_itoa(_IN_ int input, _OU_ char **output)
} }
void *kk_MutexCreate(void) void *kk_MutexCreate(void)
{ {
int err_num; int err_num;
pthread_mutex_t *mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)); pthread_mutex_t *mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
if (NULL == mutex) if (NULL == mutex)
{ {
return NULL; return NULL;
} }
if (0 != (err_num = pthread_mutex_init(mutex, NULL))) if (0 != (err_num = pthread_mutex_init(mutex, NULL)))
{ {
printf("create mutex failed\n"); printf("create mutex failed\n");
free(mutex); free(mutex);
return NULL; return NULL;
} }
return mutex; return mutex;
} }
void kk_MutexLock(void *mutex) void kk_MutexLock(void *mutex)
{ {
int err_num; int err_num;
if (0 != (err_num = pthread_mutex_lock((pthread_mutex_t *)mutex))) if (0 != (err_num = pthread_mutex_lock((pthread_mutex_t *)mutex)))
{ {
printf("lock mutex failed: - '%s' (%d)\n", strerror(err_num), err_num); printf("lock mutex failed: - '%s' (%d)\n", strerror(err_num), err_num);
} }
} }
void kk_MutexUnLock(void *mutex) void kk_MutexUnLock(void *mutex)
......
...@@ -80,8 +80,8 @@ static inline void dlist_init(dlist_t *node) ...@@ -80,8 +80,8 @@ static inline void dlist_init(dlist_t *node)
static inline void INIT_AOS_DLIST_HEAD(dlist_t *list) static inline void INIT_AOS_DLIST_HEAD(dlist_t *list)
{ {
list->next = list; list->next = list;
list->prev = list; list->prev = list;
} }
static inline int dlist_empty(const dlist_t *head) static inline int dlist_empty(const dlist_t *head)
......
...@@ -24,14 +24,14 @@ ...@@ -24,14 +24,14 @@
{ {
"opcode":"SWITCH", "opcode":"SWITCH",
"identifiermap":"PowerSwitch_1", "identifiermap":"PowerSwitch_1",
"dataType":"string", "dataType":"map",
"channel":"1", "channel":"1",
"valueRange":["OFF","ON"] "valueRange":["OFF","ON"]
}, },
{ {
"opcode":"SWITCH", "opcode":"SWITCH",
"identifiermap":"PowerSwitch_2", "identifiermap":"PowerSwitch_2",
"dataType":"string", "dataType":"map",
"channel":"2", "channel":"2",
"valueRange":["OFF","ON"] "valueRange":["OFF","ON"]
} }
......
.PHONY: doc detect config reconfig toolchain sub-mods final-out env cmake one help package squashfs firmware .PHONY: doc detect config reconfig toolchain sub-mods final-out env cmake one help package squashfs firmware
all: detect config toolchain sub-mods final-out all: detect config toolchain sub-mods final-out
$(TOP_Q) \ $(TOP_Q) \
if [ -f $(STAMP_PRJ_CFG) ]; then \ if [ -f $(STAMP_PRJ_CFG) ]; then \
$(RECURSIVE_MAKE) toolchain; \ $(RECURSIVE_MAKE) toolchain; \
rm -f $(STAMP_PRJ_CFG); \ rm -f $(STAMP_PRJ_CFG); \
fi fi
@rm -rf $(STAMP_DIR) @rm -rf $(STAMP_DIR)
RESET_ENV_VARS := \ RESET_ENV_VARS := \
CROSS_PREFIX \ CROSS_PREFIX \
CFLAGS \ CFLAGS \
HOST \ HOST \
LDFLAGS \ LDFLAGS \
help: help:
@echo -e "\033[1;37m[$(RULE_DIR)/docs]\e[0m" @echo -e "\033[1;37m[$(RULE_DIR)/docs]\e[0m"
@echo "" @echo ""
@cat $(RULE_DIR)/docs/Help.md @cat $(RULE_DIR)/docs/Help.md
@echo "" @echo ""
doc: doc:
$(TOP_Q)rm -rf $(DOXYGEN_DIR)/html; mkdir -p $(DOXYGEN_DIR) $(TOP_Q)rm -rf $(DOXYGEN_DIR)/html; mkdir -p $(DOXYGEN_DIR)
$(TOP_Q) \ $(TOP_Q) \
$(SED) \ $(SED) \
-e 's:^PROJECT_NAME.*:PROJECT_NAME = $(PRJ_NAME):g;' \ -e 's:^PROJECT_NAME.*:PROJECT_NAME = $(PRJ_NAME):g;' \
-e 's:^PROJECT_NUMBER.*:PROJECT_NUMBER = $(PRJ_VERSION):g;' \ -e 's:^PROJECT_NUMBER.*:PROJECT_NUMBER = $(PRJ_VERSION):g;' \
-e 's:^OUTPUT_DIRECTORY.*:OUTPUT_DIRECTORY = $(DOXYGEN_DIR):g;' \ -e 's:^OUTPUT_DIRECTORY.*:OUTPUT_DIRECTORY = $(DOXYGEN_DIR):g;' \
build-rules/misc/Doxyfile.tpl > $(OUTPUT_DIR)/.doxygen.cfg build-rules/misc/Doxyfile.tpl > $(OUTPUT_DIR)/.doxygen.cfg
$(TOP_Q)doxygen $(OUTPUT_DIR)/.doxygen.cfg $(TOP_Q)doxygen $(OUTPUT_DIR)/.doxygen.cfg
detect: detect:
@if [ -d .git ]; then \ @if [ -d .git ]; then \
mkdir -p .git/hooks; \ mkdir -p .git/hooks; \
for i in $(RULE_DIR)/hooks/*; do \ for i in $(RULE_DIR)/hooks/*; do \
cp -f $$i .git/hooks && chmod a+x .git/hooks/$$(basename $$i); \ cp -f $$i .git/hooks && chmod a+x .git/hooks/$$(basename $$i); \
done; \ done; \
fi fi
prune: prune:
@echo "$(TOP_DIR).pkgs directory removed!"|grep --color ".*" @echo "$(TOP_DIR).pkgs directory removed!"|grep --color ".*"
@rm -rf $(TOP_DIR).pkgs @rm -rf $(TOP_DIR).pkgs
@$(MAKE) --no-print-directory distclean @$(MAKE) --no-print-directory distclean
unzip: config $(STAMP_BLD_VAR) unzip: config $(STAMP_BLD_VAR)
@echo "Components: " @echo "Components: "
@echo "" @echo ""
@for i in $(ALL_SUB_DIRS); do \ @for i in $(ALL_SUB_DIRS); do \
$(MAKE) --no-print-directory pre-build target-$${i} ; \ $(MAKE) --no-print-directory pre-build target-$${i} ; \
echo -ne "\r. $${i}"; \ echo -ne "\r. $${i}"; \
echo -e " "; \ echo -e " "; \
done done
@echo "" @echo ""
cmake: cmake:
$(TOP_Q)$(MAKE) -s distclean $(TOP_Q)$(MAKE) -s distclean
$(TOP_Q)$(MAKE) -s DEFAULT_BLD=$(RULE_DIR)/misc/config.generic.cmake config $(TOP_Q)$(MAKE) -s DEFAULT_BLD=$(RULE_DIR)/misc/config.generic.cmake config
$(TOP_Q)$(foreach V,$(INFO_ENV_VARS),$(V)="$($(V))") CFLAGS=$(CFLAGS) \ $(TOP_Q)$(foreach V,$(INFO_ENV_VARS),$(V)="$($(V))") CFLAGS=$(CFLAGS) \
SEP_LIBS="$$(grep -m 1 '^COMP_LIB_FILES' $(STAMP_BLD_ENV) | cut -d' ' -f3-)" \ SEP_LIBS="$$(grep -m 1 '^COMP_LIB_FILES' $(STAMP_BLD_ENV) | cut -d' ' -f3-)" \
bash $(if $(TOP_Q),,-x) $(RULE_DIR)/scripts/gen_top_cmake.sh $(TOP_DIR)/CMakeLists.txt bash $(if $(TOP_Q),,-x) $(RULE_DIR)/scripts/gen_top_cmake.sh $(TOP_DIR)/CMakeLists.txt
$(TOP_Q)for D in $(ALL_SUB_DIRS); do \ $(TOP_Q)for D in $(ALL_SUB_DIRS); do \
echo "+ $${D}"; \ echo "+ $${D}"; \
$(MAKE) --no-print-directory -C $(OUTPUT_DIR)/$${D} cmake; \ $(MAKE) --no-print-directory -C $(OUTPUT_DIR)/$${D} cmake; \
done done
$(TOP_Q)echo "" $(TOP_Q)echo ""
one: COMP_LIB_OBJS = $(foreach V,$(COMP_LIB_COMPONENTS),$(foreach U,$(LIB_OBJS_$(V)),$(V)/$(U))) one: COMP_LIB_OBJS = $(foreach V,$(COMP_LIB_COMPONENTS),$(foreach U,$(LIB_OBJS_$(V)),$(V)/$(U)))
one: one:
$(TOP_Q)$(foreach V,$(INFO_ENV_VARS),$(V)="$($(V))") \ $(TOP_Q)$(foreach V,$(INFO_ENV_VARS),$(V)="$($(V))") \
CFLAGS="$(subst ",,$(CFLAGS))" \ CFLAGS="$(subst ",,$(CFLAGS))" \
ALL_LIBS="$(strip $(foreach V,$(SUBDIRS),$(LIBA_TARGET_$(V))))" \ ALL_LIBS="$(strip $(foreach V,$(SUBDIRS),$(LIBA_TARGET_$(V))))" \
ALL_LIBSO="$(strip $(foreach V,$(SUBDIRS),$(LIBSO_TARGET_$(V))))" \ ALL_LIBSO="$(strip $(foreach V,$(SUBDIRS),$(LIBSO_TARGET_$(V))))" \
ALL_PROG="$(strip $(foreach V,$(SUBDIRS) $(COMP_LIB_COMPONENTS),$(TARGET_$(V))))" \ ALL_PROG="$(strip $(foreach V,$(SUBDIRS) $(COMP_LIB_COMPONENTS),$(TARGET_$(V))))" \
COMP_LIB_OBJS="$(COMP_LIB_OBJS)" \ COMP_LIB_OBJS="$(COMP_LIB_OBJS)" \
bash $(RULE_DIR)/scripts/gen_one_makefile.sh bash $(RULE_DIR)/scripts/gen_one_makefile.sh
config: config:
@mkdir -p $(OUTPUT_DIR) $(STAMP_DIR) $(INSTALL_DIR) @mkdir -p $(OUTPUT_DIR) $(STAMP_DIR) $(INSTALL_DIR)
@mkdir -p $(SYSROOT_BIN) $(SYSROOT_INC) $(SYSROOT_LIB) @mkdir -p $(SYSROOT_BIN) $(SYSROOT_INC) $(SYSROOT_LIB)
$(TOP_Q) \ $(TOP_Q) \
if [ -f $(STAMP_BLD_VAR) ]; then \ if [ -f $(STAMP_BLD_VAR) ]; then \
if [ "$$($(SED) '/[-_/a-zA-Z0-9]* = *..*/d' $(STAMP_BLD_VAR)|wc -l|$(SED) 's:^ *::g')" != "0" ]; then \ if [ "$$($(SED) '/[-_/a-zA-Z0-9]* = *..*/d' $(STAMP_BLD_VAR)|wc -l|$(SED) 's:^ *::g')" != "0" ]; then \
rm -vf $(STAMP_BLD_VAR); \ rm -vf $(STAMP_BLD_VAR); \
fi \ fi \
fi fi
$(TOP_Q)+( \ $(TOP_Q)+( \
if [ -f $(CONFIG_TPL) ]; then \ if [ -f $(CONFIG_TPL) ]; then \
if [ "$(filter comp-lib,$(MAKECMDGOALS))" = "" ]; then \ if [ "$(filter comp-lib,$(MAKECMDGOALS))" = "" ]; then \
printf "BUILDING WITH EXISTING CONFIGURATION:\n\n"; \ printf "BUILDING WITH EXISTING CONFIGURATION:\n\n"; \
command grep -m 1 "VENDOR *:" $(CONFIG_TPL)|cut -c 3-; \ command grep -m 1 "VENDOR *:" $(CONFIG_TPL)|cut -c 3-; \
command grep -m 1 "MODEL *:" $(CONFIG_TPL)|cut -c 3-; \ command grep -m 1 "MODEL *:" $(CONFIG_TPL)|cut -c 3-; \
echo ""; \ echo ""; \
fi \ fi \
else \ else \
if ([ "$(MAKECMDGOALS)" = "all" ]) || ([ "$(DEFAULT_BLD)" != "" ] && [ -f $(DEFAULT_BLD) ] && \ if ([ "$(MAKECMDGOALS)" = "all" ]) || ([ "$(DEFAULT_BLD)" != "" ] && [ -f $(DEFAULT_BLD) ] && \
([ "$(DEFAULT_BLD)" = "$(RULE_DIR)/misc/config.generic.default" ] \ ([ "$(DEFAULT_BLD)" = "$(RULE_DIR)/misc/config.generic.default" ] \
|| [ "$(MAKECMDGOALS)" = "" ] || [ "$(MAKECMDGOALS)" = "config" ])); then \ || [ "$(MAKECMDGOALS)" = "" ] || [ "$(MAKECMDGOALS)" = "config" ])); then \
printf "# Automatically Generated Section End\n\n" >> $(CONFIG_TPL); \ printf "# Automatically Generated Section End\n\n" >> $(CONFIG_TPL); \
printf "# %-10s %s\n" "VENDOR :" $$(basename $(DEFAULT_BLD)|cut -d. -f2) >> $(CONFIG_TPL); \ printf "# %-10s %s\n" "VENDOR :" $$(basename $(DEFAULT_BLD)|cut -d. -f2) >> $(CONFIG_TPL); \
printf "# %-10s %s\n" "MODEL :" $$(basename $(DEFAULT_BLD)|cut -d. -f3) >> $(CONFIG_TPL); \ printf "# %-10s %s\n" "MODEL :" $$(basename $(DEFAULT_BLD)|cut -d. -f3) >> $(CONFIG_TPL); \
cat $(DEFAULT_BLD) >> $(CONFIG_TPL); \ cat $(DEFAULT_BLD) >> $(CONFIG_TPL); \
else \ else \
printf "SELECT A CONFIGURATION:\n\n"; \ printf "SELECT A CONFIGURATION:\n\n"; \
LIST=$$(for i in $(CONFIG_DIR)/config.*.*; do basename $${i}; done|sort); \ LIST=$$(for i in $(CONFIG_DIR)/config.*.*; do basename $${i}; done|sort); \
select V in $${LIST}; do \ select V in $${LIST}; do \
echo ""; \ echo ""; \
printf "# Automatically Generated Section End\n\n" >> $(CONFIG_TPL); \ printf "# Automatically Generated Section End\n\n" >> $(CONFIG_TPL); \
printf "# %-10s %s\n" "VENDOR :" $$(echo $${V}|cut -d. -f2) >> $(CONFIG_TPL); \ printf "# %-10s %s\n" "VENDOR :" $$(echo $${V}|cut -d. -f2) >> $(CONFIG_TPL); \
printf "# %-10s %s\n" "MODEL :" $$(echo $${V}|cut -d. -f3) >> $(CONFIG_TPL); \ printf "# %-10s %s\n" "MODEL :" $$(echo $${V}|cut -d. -f3) >> $(CONFIG_TPL); \
cp -f -P $(IMPORT_DIR)/$$(echo $${V}|cut -d. -f2)/$(PREBUILT_LIBDIR)/*.so* $(SYSROOT_LIB) 2>/dev/null; \ cp -f -P $(IMPORT_DIR)/$$(echo $${V}|cut -d. -f2)/$(PREBUILT_LIBDIR)/*.so* $(SYSROOT_LIB) 2>/dev/null; \
cat $(CONFIG_DIR)/$${V} >> $(CONFIG_TPL); \ cat $(CONFIG_DIR)/$${V} >> $(CONFIG_TPL); \
break; \ break; \
done; \ done; \
fi && \ fi && \
printf "SELECTED CONFIGURATION:\n\n" && \ printf "SELECTED CONFIGURATION:\n\n" && \
command grep -m 1 "VENDOR *:" $(CONFIG_TPL)|cut -c 3- && \ command grep -m 1 "VENDOR *:" $(CONFIG_TPL)|cut -c 3- && \
command grep -m 1 "MODEL *:" $(CONFIG_TPL)|cut -c 3- && \ command grep -m 1 "MODEL *:" $(CONFIG_TPL)|cut -c 3- && \
echo ""; \ echo ""; \
if [ "$(MAKECMDGOALS)" = "config" ]; then true; else \ if [ "$(MAKECMDGOALS)" = "config" ]; then true; else \
if [ "$(DEFAULT_BLD)" = "" ]; then \ if [ "$(DEFAULT_BLD)" = "" ]; then \
touch $(STAMP_PRJ_CFG); \ touch $(STAMP_PRJ_CFG); \
fi; \ fi; \
fi; \ fi; \
for i in $(RESET_ENV_VARS); do unset $${i}; done; \ for i in $(RESET_ENV_VARS); do unset $${i}; done; \
$(MAKE) --no-print-directory -f $(TOP_MAKEFILE) $(STAMP_BLD_VAR); \ $(MAKE) --no-print-directory -f $(TOP_MAKEFILE) $(STAMP_BLD_VAR); \
fi) fi)
@$(MAKE) --no-print-directory one @$(MAKE) --no-print-directory one
DL_TOOLCHAIN_VARS = \ DL_TOOLCHAIN_VARS = \
TOOLCHAIN_DLDIR \ TOOLCHAIN_DLDIR \
OUTPUT_DIR \ OUTPUT_DIR \
toolchain: toolchain:
@$(foreach V,$(DL_TOOLCHAIN_VARS),$(V)=$($(V))) \ @$(foreach V,$(DL_TOOLCHAIN_VARS),$(V)=$($(V))) \
CC=$(shell basename $(CC)) \ CC=$(shell basename $(CC)) \
AR=$(shell basename $(AR)) \ AR=$(shell basename $(AR)) \
RELPATH=` $(call Relative_TcPath,$(shell basename $(CC))) ` \ RELPATH=` $(call Relative_TcPath,$(shell basename $(CC))) ` \
GITPATH=` $(call Gitrepo_TcPath,$(shell basename $(CC))) ` \ GITPATH=` $(call Gitrepo_TcPath,$(shell basename $(CC))) ` \
bash $(RULE_DIR)/scripts/gen_cross_toolchain.sh bash $(RULE_DIR)/scripts/gen_cross_toolchain.sh
reconfig: distclean reconfig: distclean
$(TOP_Q)+( \ $(TOP_Q)+( \
if [ -d $(CONFIG_DIR) ]; then \ if [ -d $(CONFIG_DIR) ]; then \
$(RECURSIVE_MAKE) config DEFAULT_BLD=not-exist-actually; \ $(RECURSIVE_MAKE) config DEFAULT_BLD=not-exist-actually; \
else \ else \
$(RECURSIVE_MAKE) config; \ $(RECURSIVE_MAKE) config; \
fi) fi)
$(TOP_Q)rm -f $(STAMP_PRJ_CFG) $(TOP_Q)rm -f $(STAMP_PRJ_CFG)
clean: clean:
$(TOP_Q) \ $(TOP_Q) \
$(TOP_Q) \ $(TOP_Q) \
rm -rf \ rm -rf \
$(LIBOBJ_TMPDIR) \ $(LIBOBJ_TMPDIR) \
$(COMPILE_LOG) \ $(COMPILE_LOG) \
$(DIST_DIR)/* \ $(DIST_DIR)/* \
$(STAMP_DIR) \ $(STAMP_DIR) \
$(STAMP_LCOV) \ $(STAMP_LCOV) \
$(SYSROOT_INC)/* $(SYSROOT_LIB)/* $(SYSROOT_LIB)/../bin/* \ $(SYSROOT_INC)/* $(SYSROOT_LIB)/* $(SYSROOT_LIB)/../bin/* \
$(shell $(SHELL_DBG) find $(OUTPUT_DIR) -name "$(COMPILE_LOG)" \ $(shell $(SHELL_DBG) find $(OUTPUT_DIR) -name "$(COMPILE_LOG)" \
-or -name "$(WARNING_LOG)" \ -or -name "$(WARNING_LOG)" \
-or -name "$(STAMP_BUILD)" \ -or -name "$(STAMP_BUILD)" \
-or -name "$(STAMP_INSTALL)" \ -or -name "$(STAMP_INSTALL)" \
-or -name "$(STAMP_POSTINS)" \ -or -name "$(STAMP_POSTINS)" \
-or -name "*.so" \ -or -name "*.so" \
-or -name "*.a" \ -or -name "*.a" \
-or -name "*.o" \ -or -name "*.o" \
-or -name "*.d" \ -or -name "*.d" \
-or -name "*.gc*" \ -or -name "*.gc*" \
| grep -v '$(OUTPUT_DIR)/compiler' \ | grep -v '$(OUTPUT_DIR)/compiler' \
2>/dev/null) 2>/dev/null)
distclean: distclean:
$(TOP_Q) \ $(TOP_Q) \
rm -rf \ rm -rf \
$(CONFIG_TPL) $(COMPILE_LOG) \ $(CONFIG_TPL) $(COMPILE_LOG) \
$(STAMP_PRJ_CFG) $(STAMP_BLD_ENV) $(STAMP_BLD_VAR) $(STAMP_POST_RULE) $(STAMP_LCOV) \ $(STAMP_PRJ_CFG) $(STAMP_BLD_ENV) $(STAMP_BLD_VAR) $(STAMP_POST_RULE) $(STAMP_LCOV) \
$(DIST_DIR) $(STAMP_DIR) *.gcda \ $(DIST_DIR) $(STAMP_DIR) *.gcda \
$(TOP_Q) \ $(TOP_Q) \
if [ -d $(OUTPUT_DIR) ]; then \ if [ -d $(OUTPUT_DIR) ]; then \
cd $(OUTPUT_DIR); \ cd $(OUTPUT_DIR); \
if [ "$(CONFIG_TOOLCHAIN_NAME)" = "" ]; then \ if [ "$(CONFIG_TOOLCHAIN_NAME)" = "" ]; then \
rm -rf *; \ rm -rf *; \
else \ else \
rm -rf $$(ls -I $(CONFIG_TOOLCHAIN_NAME)); \ rm -rf $$(ls -I $(CONFIG_TOOLCHAIN_NAME)); \
fi \ fi \
fi fi
#buildDate=$(shell date "+%Y.%m.%d") #buildDate=$(shell date "+%Y.%m.%d")
releaseDir=kk releaseDir=kk
package: package:
@echo "$(buildDate)" @echo "$(buildDate)"
echo "$(releaseDir)" echo "$(releaseDir)"
rm -rf $(releaseDir) rm -rf $(releaseDir)
mkdir $(releaseDir) mkdir $(releaseDir)
mkdir $(releaseDir)/lib mkdir $(releaseDir)/lib
mkdir $(releaseDir)/bin mkdir $(releaseDir)/bin
cp -rf $(TOP_DIR)/tsl $(TOP_DIR)/$(releaseDir) cp -rf $(TOP_DIR)/tsl $(TOP_DIR)/$(releaseDir)
cp -rf $(TOP_DIR)/output/release/lib/*.so $(TOP_DIR)/$(releaseDir)/lib cp -rf $(TOP_DIR)/output/release/lib/*.so $(TOP_DIR)/$(releaseDir)/lib
cp -rf $(TOP_DIR)/output/release/bin/* $(TOP_DIR)/$(releaseDir)/bin cp -rf $(TOP_DIR)/output/release/bin/* $(TOP_DIR)/$(releaseDir)/bin
cp -rf $(TOP_DIR)/process_check.sh $(TOP_DIR)/$(releaseDir)/ cp -rf $(TOP_DIR)/process_check.sh $(TOP_DIR)/$(releaseDir)/
#cp -rf $(TOP_DIR)/platform/zigbee/app/builder/Z3GatewayHost/ZB/dev_config_table $(TOP_DIR)/$(releaseDir)/ #cp -rf $(TOP_DIR)/platform/zigbee/app/builder/Z3GatewayHost/ZB/dev_config_table $(TOP_DIR)/$(releaseDir)/
#cp -rf $(TOP_DIR)/platform/zigbee/app/builder/Z3GatewayHost/ZB/dev_map_table.json $(TOP_DIR)/$(releaseDir)/dev_config_table/ #cp -rf $(TOP_DIR)/platform/zigbee/app/builder/Z3GatewayHost/ZB/dev_map_table.json $(TOP_DIR)/$(releaseDir)/dev_config_table/
ifeq ($(CONFIG_MODEL),ubuntu) ifeq ($(CONFIG_MODEL),ubuntu)
cp -rf $(TOP_DIR)/common/nanomsg/libnanomsg_ubuntu.so $(TOP_DIR)/$(releaseDir)/lib/libnanomsg.so.5 cp -rf $(TOP_DIR)/common/nanomsg/libnanomsg_ubuntu.so $(TOP_DIR)/$(releaseDir)/lib/libnanomsg.so.5
cp -rf $(TOP_DIR)/common/ev/libev_ubuntu.so $(TOP_DIR)/$(releaseDir)/lib cp -rf $(TOP_DIR)/common/ev/libev_ubuntu.so $(TOP_DIR)/$(releaseDir)/lib
else ifeq ($(CONFIG_MODEL),nx5) else ifeq ($(CONFIG_MODEL),nx5)
cp -rf $(TOP_DIR)/common/nanomsg/libnanomsg_nx5.so $(TOP_DIR)/$(releaseDir)/lib cp -rf $(TOP_DIR)/common/nanomsg/libnanomsg_nx5.so $(TOP_DIR)/$(releaseDir)/lib
cp -rf $(TOP_DIR)/common/ev/libev_nx5.so $(TOP_DIR)/$(releaseDir)/lib cp -rf $(TOP_DIR)/common/ev/libev_nx5.so $(TOP_DIR)/$(releaseDir)/lib
cp -rf $(TOP_DIR)/common/sqlite/libsqlite3.so $(TOP_DIR)/$(releaseDir)/lib cp -rf $(TOP_DIR)/common/sqlite/libsqlite3.so $(TOP_DIR)/$(releaseDir)/lib
else else
cp -rf $(TOP_DIR)/common/nanomsg/libnanomsg.so $(TOP_DIR)/$(releaseDir)/lib cp -rf $(TOP_DIR)/common/nanomsg/libnanomsg.so $(TOP_DIR)/$(releaseDir)/lib
cp -rf $(TOP_DIR)/common/ev/libev.so $(TOP_DIR)/$(releaseDir)/lib cp -rf $(TOP_DIR)/common/ev/libev.so $(TOP_DIR)/$(releaseDir)/lib
cp -rf $(TOP_DIR)/common/sqlite/libsqlite3.so $(TOP_DIR)/$(releaseDir)/lib cp -rf $(TOP_DIR)/common/sqlite/libsqlite3.so $(TOP_DIR)/$(releaseDir)/lib
endif endif
cp -rf $(TOP_DIR)/platform/zigbee/app/builder/Z3GatewayHost/build/exe/Z3GatewayHost $(TOP_DIR)/$(releaseDir)/ cp -rf $(TOP_DIR)/platform/zigbee/app/builder/Z3GatewayHost/build/exe/Z3GatewayHost $(TOP_DIR)/$(releaseDir)/
fromdos $(releaseDir)/*.sh fromdos $(releaseDir)/*.sh
echo $(PWD) echo $(PWD)
squashfs: package squashfs: package
@echo "build squashfs" @echo "build squashfs"
rm -rf kkdir kkdir.squashfs rm -rf kkdir kkdir.squashfs
mkdir kkdir mkdir kkdir
cp -rf $(TOP_DIR)/$(releaseDir) $(TOP_DIR)/kkdir/ cp -rf $(TOP_DIR)/$(releaseDir) $(TOP_DIR)/kkdir/
cp -rf $(TOP_DIR)/app.sh $(TOP_DIR)/kkdir/ cp -rf $(TOP_DIR)/app.sh $(TOP_DIR)/kkdir/
TOP_DIR='$(TOP_DIR)' $(TOP_DIR)/tools/mk2fs/mk2fs.sh TOP_DIR='$(TOP_DIR)' $(TOP_DIR)/tools/mk2fs/mk2fs.sh
rm -rf kkdir kkdir.squashfs rm -rf kkdir kkdir.squashfs
echo $(PWD) echo $(PWD)
firmware: firmware:
@echo "build firmware" @echo "build firmware"
ifneq (ap86-key-factory.bin, $(wildcard ap86-key-factory.bin)) ifneq (ap86-key-factory.bin, $(wildcard ap86-key-factory.bin))
@echo "================请把包括产测的固件ap86-key-factory.bin放在当前目录下=================" @echo "================请把包括产测的固件ap86-key-factory.bin放在当前目录下================="
exit 1 exit 1
endif endif
cp -rf $(TOP_DIR)/ap86-key-factory.bin $(TOP_DIR)/tools/mk2fs/ cp -rf $(TOP_DIR)/ap86-key-factory.bin $(TOP_DIR)/tools/mk2fs/
cd $(TOP_DIR)/tools/mk2fs/ && ./mkfirmware-ap86-key.sh cd $(TOP_DIR)/tools/mk2fs/ && ./mkfirmware-ap86-key.sh
mv $(TOP_DIR)/tools/mk2fs/ap86-key-new-zone-factory-burn-firmware.bin $(TOP_DIR)/ mv $(TOP_DIR)/tools/mk2fs/ap86-key-new-zone-factory-burn-firmware.bin $(TOP_DIR)/
rm $(TOP_DIR)/tools/mk2fs/ap86-key-factory.bin rm $(TOP_DIR)/tools/mk2fs/ap86-key-factory.bin
@echo "build firmware success" @echo "build firmware success"
ifeq ($(shell uname),Darwin) ifeq ($(shell uname),Darwin)
KCONFIG_MCONF := tools/prebuilt/macos/kconfig-frontends-mac/kconfig-mconf KCONFIG_MCONF := tools/prebuilt/macos/kconfig-frontends-mac/kconfig-mconf
else else
KCONFIG_MCONF := tools/prebuilt/ubuntu/bin/kconfig-mconf KCONFIG_MCONF := tools/prebuilt/ubuntu/bin/kconfig-mconf
endif endif
COMMON_CONFIG_ENV = \ COMMON_CONFIG_ENV = \
KCONFIG_CONFIG=mconf.config \ KCONFIG_CONFIG=mconf.config \
KCONFIG_AUTOCONFIG=$(OUTPUT_DIR)/auto.conf \ KCONFIG_AUTOCONFIG=$(OUTPUT_DIR)/auto.conf \
KCONFIG_AUTOHEADER=$(OUTPUT_DIR)/autoconf.h \ KCONFIG_AUTOHEADER=$(OUTPUT_DIR)/autoconf.h \
CONFIG_=FEATURE_ \ CONFIG_=FEATURE_ \
menuconfig: $(KCONFIG_MCONF) menuconfig: $(KCONFIG_MCONF)
$(TOP_Q)chmod a+x $(KCONFIG_MCONF) $(if $(TOP_Q),2>/dev/null) || true $(TOP_Q)chmod a+x $(KCONFIG_MCONF) $(if $(TOP_Q),2>/dev/null) || true
$(TOP_Q)$(COMMON_CONFIG_ENV) $^ -s $(TOP_DIR)/tools/Config.in $(if $(TOP_Q),2>/dev/null) $(TOP_Q)$(COMMON_CONFIG_ENV) $^ -s $(TOP_DIR)/tools/Config.in $(if $(TOP_Q),2>/dev/null)
$(TOP_Q) \ $(TOP_Q) \
( \ ( \
if [ ! -f mconf.config ]; then exit 0; fi; \ if [ ! -f mconf.config ]; then exit 0; fi; \
\ \
cp -Lf mconf.config make.settings; \ cp -Lf mconf.config make.settings; \
rm -f mconf.config*; \ rm -f mconf.config*; \
) )
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