Commit 93d95f0b authored by 陈伟灿's avatar 陈伟灿

Merge branch 'cwc' into 'master'

Cwc

See merge request chenweican/k-sdk!118
parents 4d9d15b7 298ae08d
......@@ -60,24 +60,24 @@ static int kk_info_get(char *str)
{
char status[4] = {0};
cJSON_AddItemToObject(args, "ccu", ccu);
cJSON_AddStringToObject(ccu, "id", &ccuid[4]);
cJSON_AddStringToObject(ccu, "version", version);
cJSON_AddStringToObject(ccu, "name", "kk_new_ccu");
//INFO_PRINT("---222kk_get_cloud_status():%d\n",kk_get_cloud_status());
//if(kk_get_gw_status() == DEVICE_OFFLINE){
//memcpy(status,"2",strlen("2"));
//}
if(kk_get_cloud_status() == DEVICE_OFFLINE)
{
//cJSON_AddStringToObject(ccu, "status", "1");
//INFO_PRINT("_-----------------------------------------------------------11\n");
memcpy(status,"1",strlen("1"));
}else{
//INFO_PRINT("_-----------------------------------------------------------22\n");
memcpy(status,"0",strlen("0"));
}
//INFO_PRINT("------------------------------------->status :%s\n",status);
cJSON_AddItemToObject(args, "ccu", ccu);
cJSON_AddStringToObject(ccu, "id", &ccuid[4]);
cJSON_AddStringToObject(ccu, "version", "1.1.1");
cJSON_AddStringToObject(ccu, "name", "kk_new_ccu");
//INFO_PRINT("---222kk_get_cloud_status():%d\n",kk_get_cloud_status());
//if(kk_get_gw_status() == DEVICE_OFFLINE){
//memcpy(status,"2",strlen("2"));
//}
if(kk_get_cloud_status() == DEVICE_OFFLINE)
{
//cJSON_AddStringToObject(ccu, "status", "1");
//INFO_PRINT("_-----------------------------------------------------------11\n");
memcpy(status,"1",strlen("1"));
}else{
//INFO_PRINT("_-----------------------------------------------------------22\n");
memcpy(status,"0",strlen("0"));
}
//INFO_PRINT("------------------------------------->status :%s\n",status);
cJSON_AddStringToObject(ccu, "status", status);
}
......
......@@ -115,16 +115,15 @@ void KK_reset_sub_flag(void)
int KK_CCU_TOPIC_Subscribe(void)
{
char productCode[PRODUCT_CODE_LEN] = {0};
char deviceCode[MAC_ADDR_LEN] = {0};
if(s_ccu_topic_sub == 1){
INFO_PRINT("[%s][%d] already Subscribe\n",__FUNCTION__,__LINE__);
return -1;
//return -1;
}
char ccuid[32] = {0};
KK_Get_ccuid(ccuid);
s_ccu_topic_sub = 1;
HAL_GetProduct_Code(productCode);
HAL_Get_mac(deviceCode);
return _kk_ccu_topic_subscribe(productCode,ccuid);
}
......
......@@ -198,8 +198,8 @@ int devOpen(char *dev)
if(fd == -1)
{
SERIAL_LOG_ERR("devOpen %s\n ",dev);
perror("devOpen");
//SERIAL_LOG_ERR("devOpen %s\n ",dev);
//perror("devOpen");
return -1;
}
......
......@@ -115,7 +115,27 @@ cJSON * kk_control_protocol_convert(kk_map_dev_node_t *devNode,int nodeId,cJSON
return params;
}
static int kk_guard_ctrl_handle(int status)
{
char ccuid[33]={0};
kk_lan_get_ccuid(ccuid);
cJSON *root = cJSON_CreateObject();
cJSON *params = cJSON_CreateObject();
cJSON_AddStringToObject(params,"epNum","1");
if(status == 0){ //
cJSON_AddStringToObject(params,"ArmingState","0");
}else if(status == 2){ //ڼ
cJSON_AddStringToObject(params,"ArmingState","2");
}else{ //
cJSON_AddStringToObject(params,"ArmingState","1");
}
cJSON *info = property_info_build("/thing/service/property/set",KK_CCU_PRODUCTID,ccuid);
cJSON *payload = property_payload_build("thing.service.property.set","1","v1.0",params);
cJSON_AddItemToObject(root,INFO_STRING,info);
cJSON_AddItemToObject(root,PAYLOAD_STRING,payload);
kk_ipc_send_json(root);
return 0;
}
static int kk_indoorAir_ctrl_handle(char *epNum,cJSON *arg)
{
kk_map_dev_node_t *dev = NULL;
......@@ -202,6 +222,17 @@ int kk_ccu_opcode_handle(cJSON *root)
kk_indoorAir_ctrl_handle(nodeId->valuestring,arg);
return 0;
}else if(strcmp(requester->valuestring,"HJ_Server") == 0){
if(strcmp(opcode->valuestring,"ARMING_IN_HOME") == 0){
kk_guard_ctrl_handle(2);
return 0;
}else if(strcmp(opcode->valuestring,"ARMING_LEAVE_HOME") == 0){
kk_guard_ctrl_handle(0);
return 0;
}else if(strcmp(opcode->valuestring,"DISARMING") == 0){
kk_guard_ctrl_handle(1);
return 0;
}
}
}
......
......@@ -315,7 +315,7 @@ void *kk_vp_manage_thread(void *arg)
break;
case UPDATING_8009_CONFIG_FILE_INFO:
debug_log(LOG_INFO_LEVEL,"updating...\n");
//debug_log(LOG_INFO,"updating...\n");
sleep(1);
//todo :超时取消
break;
......
This diff is collapsed.
......@@ -1239,7 +1239,52 @@ int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params)
return SUCCESS_RETURN;
}
int kk_msg_cloud_status_notify(const char *deviceCode,const char *productCode)
{
char *method = "thing.service.cloudStatus";
char *req_info = NULL,*payload = NULL;
int req_info_len = 0,payload_len = 0;
char msgId[MSG_MAX_LEN] = {0};
req_info_len = strlen(DM_MSG_INFO)+10+strlen(deviceCode)+strlen(productCode)+strlen(KK_THING_SERVICE_CLOUDSTATUS)+1;
req_info = malloc(req_info_len);
if (req_info == NULL) {
return MEMORY_NOT_ENOUGH;
}
memset(req_info, 0, req_info_len);
snprintf(req_info, req_info_len, DM_MSG_INFO, KK_THING_SERVICE_CLOUDSTATUS,productCode, deviceCode);
cJSON *params=cJSON_CreateObject();
cJSON_AddNumberToObject(params, "status", 1);
char *paramStr = cJSON_Print(params);
payload_len = strlen(DM_MSG_REQUEST) + 10 + strlen(DM_MSG_VERSION) + strlen(paramStr) + strlen(
method) + 1 + 20 + sizeof(msgId);
payload = malloc(payload_len);
if (payload == NULL) {
free(req_info);
return MEMORY_NOT_ENOUGH;
}
memset(payload, 0, payload_len);
iotx_report_id(msgId);
//sprintf(msgId,"%d",iotx_report_id());
snprintf(payload, payload_len, DM_MSG_REQUEST, msgId,
DM_MSG_VERSION, paramStr,HAL_GetTime(), method);
cJSON *root=cJSON_CreateObject();
cJSON* infoObj = cJSON_Parse(req_info);
cJSON* payloadObj = cJSON_Parse(payload);
cJSON_AddItemToObject(root, "info", infoObj);
cJSON_AddItemToObject(root, "payload",payloadObj);
void *buf = cJSON_Print(root);
printf("------------------------------------------------------->333\n");
kk_sendData2gw(buf, strlen(buf), deviceCode);
free(paramStr);
free(buf);
free(req_info);
free(payload);
cJSON_Delete(params);
cJSON_Delete(root);
return SUCCESS_RETURN;
}
int kk_msg_execute_property_set(const char *productCode,const char *deviceCode,const char* params,const char *fatherDeviceCode)
{
char *method = "thing.service.property.set";
......
......@@ -85,7 +85,7 @@ const char DM_MSG_INFO[] DM_READ_ONLY;
#define KK_THING_SERVICE_SYNCINFO "/thing/service/syncinfo"
#define KK_THING_SERVICE_SYNCDEVICEINFO "/thing/service/syncDeviceInfo"
#define KK_THING_SERVICE_SYNCDEVICEINFO_REPLY "/thing/service/syncDeviceInfo_reply"
#define KK_THING_SERVICE_CLOUDSTATUS "/thing/service/cloudStatus"
......
......@@ -56,7 +56,7 @@
static int s_gateway_add_flag = 0;
typedef struct {
int msgid;
......@@ -351,10 +351,10 @@ int kk_topo_delete_handle(cJSON *payload,cJSON *buf)
cJSON_AddItemToObject(rootData,"payload",payload);
char *pnewout=cJSON_Print(rootData);
kk_sendData2gw(pnewout, strlen(pnewout), node->fatherDeviceCode);//send to gw itself
free(pnewout);
cJSON_Delete(rootData);
dm_mgr_subdev_delete(deviceCode);
item = item->next;
free(pnewout);
//cJSON_Delete(rootData);
return SUCCESS_RETURN;
}
}
......@@ -1094,9 +1094,10 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
char *payload_Str = NULL;
cJSON *deviceCode = NULL;
json=cJSON_Parse(data);
_iotx_linkkit_mutex_lock();
if (json == NULL) {
WARNING_PRINT("Error before: [%s]\n","cJSON_Parse");
_iotx_linkkit_mutex_unlock();
return;
}
info_root = cJSON_GetObjectItem(json, MSG_INFO_STR);
......@@ -1195,7 +1196,8 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
node->isOffline = KK_DEV_ONLINE;
dm_mgr_upstream_thing_sub_register(KK_DM_DEVICE_CCU_DEVICEID);
iotx_dm_dev_online(KK_DM_DEVICE_CCU_DEVICEID);//first online,report the online status
usleep(200000);
if(s_gateway_add_flag == 0)
kk_subDev_check_auth(KK_DM_DEVICE_GATEWAY);
dm_msg_ccu_property_post(node);
dm_mgr_resubscribe();
}
......@@ -1370,6 +1372,7 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
directReturn:
free(payload_Str);
cJSON_Delete(json);
_iotx_linkkit_mutex_unlock();
}
/************************************************************
......@@ -1765,7 +1768,15 @@ int kk_mid_subdev_add(int devType, char productCode[PRODUCT_CODE_MAXLEN], char d
}
kk_subDev_update_productType(node->productType,deviceCode);
}
if(devType == KK_DM_DEVICE_GATEWAY){//如果还没有连上云,网关topo add不处理
if(s_CloudStatus){
//kk_subDev_update_auth(1,deviceCode);
s_gateway_add_flag = 1;
}else{
ERROR_PRINT("Cloud is not connected!!!!!!!!\n");
return FAIL_RETURN;
}
}
_iotx_linkkit_mutex_lock();
res = _iotx_linkkit_slave_connect(devid);
if (res != SUCCESS_RETURN) {
......
......@@ -228,8 +228,6 @@ static int _kk_check_door_induction_device(char *productCode){
int kk_property_db_insert(const char *deviceCode,const char *identifier,kk_tsl_data_type_e valuetype,int devtype)
{
printf("---------------------------------------->identifier:%s\n",identifier);
dm_mgr_dev_node_t *node = NULL;
int res = 0 ;
const char *insertCmd = "insert into PropertiesInfo (deviceCode,identifier,value,valueType,devType) \
......@@ -238,12 +236,10 @@ int kk_property_db_insert(const char *deviceCode,const char *identifier,kk_tsl_d
int rc = 0;
char *zErrMsg = 0;
kk_property_db_ctx_t *ctx = _kk_property_db_get_ctx();
printf("---------------------------------------->1\n");
if(_kk_check_property_exist(deviceCode,identifier) == 1)
{
return SUCCESS_RETURN;
}
printf("---------------------------------------->2\n");
_kk_property_db_lock();
//传感器类默认安防等级为离家安防
if(strcmp(identifier,"SensorType") == 0 && devtype == KK_DM_DEVICE_SUBDEV){
......@@ -251,12 +247,10 @@ int kk_property_db_insert(const char *deviceCode,const char *identifier,kk_tsl_d
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
printf("---------------------------------------->3\n");
if(_kk_check_human_induction_device(node->productCode) == 1 || //门磁和人体默认室外安防
_kk_check_door_induction_device(node->productCode) == 1){
sqlCmd = sqlite3_mprintf(insertCmd,deviceCode,identifier,"1",valuetype,devtype);
}else{
printf("---------------------------------------->\n");
sqlCmd = sqlite3_mprintf(insertCmd,deviceCode,identifier,"2",valuetype,devtype);//其他24小时警戒
}
}else{
......
......@@ -385,7 +385,36 @@ int kk_subDev_update_auth(int isAuth,const char *deviceCode)
_kk_subDb_unlock();
return SUCCESS_RETURN;
}
/************************************************************
*功能描述:更新设备注册标记
*输入参数:deviceCode:设备deviceCode
isAuth:1,已注册;0,未注册
*输出参数:无
*返 回 值:0:成功;其他:失败
*其他说明:
*************************************************************/
int kk_subDev_check_auth(int devType)
{
char *sqlCmd = NULL;
sqlite3_stmt *stmt;
int rc = 0;
char *zErrMsg = 0;
const char *searchCmd = "select * from SubDeviceInfo WHERE devType = '%d';";
kk_subDb_ctx_t *ctx = _kk_subDb_get_ctx();
printf("------------------------------------------------------->111\n");
sqlCmd = sqlite3_mprintf(searchCmd,devType);
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
printf("------------------------------------------------------->222\n");
char *pDeviceCode = (char*)sqlite3_column_text(stmt, DB_SUB_DEVICECODE);
char *pProductCode = (char*)sqlite3_column_text(stmt, DB_SUB_PRODUCTCODE);
kk_msg_cloud_status_notify(pProductCode,pDeviceCode);
//kk_subDev_update_auth(1,pDeviceCode);
}
sqlite3_finalize(stmt);
sqlite3_free(sqlCmd);
return SUCCESS_RETURN;
}
/************************************************************
*功能描述:更新内场景支持,此接口只针对网关设备有效
*输入参数:deviceCode:设备deviceCode
......
......@@ -15,7 +15,6 @@ int kk_subDev_update_auth(int isAuth,const char *deviceCode);
int kk_subDev_update_sceneSupport(int sceneSupport,const char *deviceCode);
int kk_subDev_delete_by_dcode(char deviceCode[DEVICE_CODE_MAXLEN]);
int kk_subDev_update_productType(char *productType,const char *deviceCode);
int kk_subDev_update_auth(int isAuth,const char *deviceCode);
int kk_subDev_send_property_get_from_db(void);
int kk_subDev_send_property_get(const char *fatherDeviceCode);
......@@ -24,6 +23,7 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *scen
int kk_subDev_update_offline(int isOffline,const char *deviceCode);
int kk_subDev_getSensors_reply(SensorType_t*list);
int kk_load_subDevice(void);
int kk_subDev_check_auth(int devType);
enum{
DB_SUB_IDX = 0,
DB_SUB_ONLINE,
......
......@@ -783,6 +783,7 @@ void kk_platMsg_handle(void* data, char* chalMark){
if(sceneSupportStr != NULL&&!strcmp(sceneSupportStr->valuestring,"1")){
kk_subDev_update_sceneSupport(1,devCode->valuestring);
}
kk_dm_gw_status_update_online(info_dcode->valuestring);
}else{
kk_mid_subdev_add(KK_DM_DEVICE_SUBDEV,proCode->valuestring,devCode->valuestring, mac->valuestring,info_dcode->valuestring);
}
......
#!/bin/sh
#filepath="/home/kk"
filepath="/app/ccuApps"
if [ ! -f "/sbin/jq" ]
then
cp /app/ccuApps/jq /sbin
cp $filepath/jq /sbin
fi
if [ -f "/app/nx5Apps/syscfg.json" ]
then
......@@ -19,9 +21,9 @@ then
fi
fi
nanomsg_File="/app/ccuApps/lib/libnanomsg.so.5"
ev_File="/app/ccuApps/lib/libev.so.4"
sqlite_File="/app/ccuApps/lib/libsqlite3.so.0"
nanomsg_File="$filepath/lib/libnanomsg.so.5"
ev_File="$filepath/lib/libev.so.4"
sqlite_File="$filepath/lib/libsqlite3.so.0"
run_Dir="/data/kk"
tsl_Dir="${run_Dir}/tsl"
......@@ -38,36 +40,36 @@ if [ ! -d "$run_Dir" ]; then
fi
if [ ! -d "$tsl_Dir" ]; then
cp -rf /app/ccuApps/tsl ${run_Dir}/
cp -rf $filepath/tsl ${run_Dir}/
fi
if [ ! -d "$map_Dir" ]; then
cp -rf /app/ccuApps/map ${run_Dir}/
cp -rf $filepath/map ${run_Dir}/
fi
cd /app/ccuApps/lib
cd $filepath/lib
if [ ! -f "$nanomsg_File" ]; then
ln -sf /app/ccuApps/lib/libnanomsg.so /lib/libnanomsg.so.5
ln -sf $filepath/lib/libnanomsg.so /lib/libnanomsg.so.5
fi
if [ ! -f "$ev_File" ]; then
ln -sf /app/ccuApps/lib/libev.so /lib/libev.so.4
ln -sf $filepath/lib/libev.so /lib/libev.so.4
fi
if [ ! -f "$sqlite_File" ]; then
ln -sf /app/ccuApps/lib/libsqlite3.so /lib/libsqlite3.so.0
ln -sf $filepath/lib/libsqlite3.so /lib/libsqlite3.so.0
fi
export LD_LIBRARY_PATH=/app/ccuApps/lib
export LD_LIBRARY_PATH=$filepath/lib
/app/ccuApps/bin/kk_midware &
$filepath/bin/kk_midware &
sleep 3
/app/ccuApps/bin/kk_cloud &
sleep 1
$filepath/bin/kk_cloud &
sleep 5
#/home/kk/process_check.sh >/dev/null 2>&1 &
/app/ccuApps/bin/smarthome_z3gw_nx5 -r0 -l3 --device-def=/app/ccuApps/kk_device_def.json --db=/data/kk/kk_z3gw.db --uart=/dev/ttyS1&
$filepath/bin/smarthome_z3gw_nx5 -r0 -l3 --device-def=$filepath/kk_device_def.json --db=/data/kk/kk_z3gw.db --uart=/dev/ttyS1&
sleep 2
/app/ccuApps/bin/kk_lan &
$filepath/bin/kk_lan --uart=/dev/ttyS3&
sleep 1
echo "*/1 * * * * /app/ccuApps/process_check.sh" > /etc/cron.d/ccu || { echo "ERROR:add ccu crontab rule failed."; exit 1;}
#echo "*/1 * * * * /app/ccuApps/process_check.sh" > /etc/cron.d/ccu || { echo "ERROR:add ccu crontab rule failed."; exit 1;}
ntpd -n -q -d -p stdtime.gov.hk &
exit 0
\ No newline at end of file
......@@ -210,6 +210,7 @@ package:
cp -rf $(TOP_DIR)/process_check.sh $(TOP_DIR)/$(releaseDir)/
cp -rf $(TOP_DIR)/onboot.sh $(TOP_DIR)/$(releaseDir)/
cp -rf $(TOP_DIR)/killall.sh $(TOP_DIR)/$(releaseDir)/
cp -rf $(TOP_DIR)/VERSION $(TOP_DIR)/$(releaseDir)/
cp -rf $(TOP_DIR)/opcodeMapCfg/* $(TOP_DIR)/$(releaseDir)/map
#cp -rf $(TOP_DIR)/platform/zigbee/app/builder/Z3GatewayHost/ZB/dev_config_table $(TOP_DIR)/$(releaseDir)/
......@@ -218,6 +219,7 @@ 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/ev/libev_ubuntu.so $(TOP_DIR)/$(releaseDir)/lib
else ifeq ($(CONFIG_MODEL),nx5)
cp -rf $(TOP_DIR)/jq $(TOP_DIR)/$(releaseDir)/
cp -rf $(TOP_DIR)/common/nanomsg/libnanomsg_nx5.so $(TOP_DIR)/$(releaseDir)/lib/libnanomsg.so
cp -rf $(TOP_DIR)/common/ev/libev_nx5.so $(TOP_DIR)/$(releaseDir)/lib/libev.so
cp -rf $(TOP_DIR)/common/sqlite/libsqlite3_nx5.so $(TOP_DIR)/$(releaseDir)/lib/libsqlite3.so
......
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