Commit faeb96b8 authored by chen.weican's avatar chen.weican

【修改内容】1,增加软件多控机制

【提交人】陈伟灿
parent 652f80d7
...@@ -175,8 +175,6 @@ static int mqtt_start(void) ...@@ -175,8 +175,6 @@ static int mqtt_start(void)
count = 0; count = 0;
WARNING_PRINT("---------------------------------->CONNECT FAIL!!!\n"); WARNING_PRINT("---------------------------------->CONNECT FAIL!!!\n");
break; break;
//INFO_PRINT("i am send now\n");
//KK_MQTT_SendMsg(TOPIC,"hello my world",2);
} }
}else{ }else{
if(count > 0){ if(count > 0){
...@@ -199,7 +197,7 @@ static int mqtt_start_ex(int isdefault) ...@@ -199,7 +197,7 @@ static int mqtt_start_ex(int isdefault)
MQTTAsync mqttClient; MQTTAsync mqttClient;
int rc = 0; int rc = 0;
if(isdefault){ if(isdefault){
mqttClient = kk_connect_default(); //mqttClient = kk_connect_default();
}else{ }else{
mqttClient = kk_mqtt_connect(); mqttClient = kk_mqtt_connect();
} }
...@@ -213,13 +211,10 @@ static int mqtt_start_ex(int isdefault) ...@@ -213,13 +211,10 @@ static int mqtt_start_ex(int isdefault)
if(kk_get_cloud_status() == 0){ if(kk_get_cloud_status() == 0){
//printf("------------------------------>count:%d\n",count); //printf("------------------------------>count:%d\n",count);
count++; count++;
if(count>500) if(count>50){
{
count = 0; count = 0;
WARNING_PRINT("---------------------------------->CONNECT FAIL!!!\n"); WARNING_PRINT("---------------------------------->CONNECT FAIL!!!\n");
break; break;
//INFO_PRINT("i am send now\n");
//KK_MQTT_SendMsg(TOPIC,"hello my world",2);
} }
}else{ }else{
if(count > 0){ if(count > 0){
...@@ -319,8 +314,8 @@ int main(int argc, char* argv[]) ...@@ -319,8 +314,8 @@ int main(int argc, char* argv[])
#endif #endif
kk_ipc_init(IPC_APP2MID,(ipc_cb*)KK_Data_FromDev,NULL,NULL); kk_ipc_init(IPC_APP2MID,(ipc_cb*)KK_Data_FromDev,NULL,NULL);
#if 1 #if 1
kk_dl_config();
again: again:
kk_dl_config();
rc = kk_register_auth_get(); rc = kk_register_auth_get();
if(rc == 0){ if(rc == 0){
rc = mqtt_start_ex(0); rc = mqtt_start_ex(0);
......
...@@ -477,6 +477,7 @@ static int _kk_parse_auth_dl_host(cJSON *authInfo,char *url){ ...@@ -477,6 +477,7 @@ static int _kk_parse_auth_dl_host(cJSON *authInfo,char *url){
} }
static int _kk_get_auth_dl_host(char *buf,char *url){ static int _kk_get_auth_dl_host(char *buf,char *url){
cJSON *authInfo = NULL; cJSON *authInfo = NULL;
int ret = 0;
if(buf == NULL || url == NULL){ if(buf == NULL || url == NULL){
return -1; return -1;
} }
...@@ -490,9 +491,9 @@ static int _kk_get_auth_dl_host(char *buf,char *url){ ...@@ -490,9 +491,9 @@ static int _kk_get_auth_dl_host(char *buf,char *url){
}else{ }else{
authInfo = cJSON_GetObjectItem(data,"mqtt_auth_entry"); authInfo = cJSON_GetObjectItem(data,"mqtt_auth_entry");
} }
_kk_parse_auth_dl_host(authInfo,url); ret = _kk_parse_auth_dl_host(authInfo,url);
cJSON_Delete(configObj); cJSON_Delete(configObj);
return 0; return ret;
} }
static int s_getAuthSize = 0; static int s_getAuthSize = 0;
size_t receive_auth_data(void *buffer, size_t size, size_t nmemb, FILE *file){ size_t receive_auth_data(void *buffer, size_t size, size_t nmemb, FILE *file){
...@@ -531,16 +532,8 @@ int kk_register_auth_get(){ ...@@ -531,16 +532,8 @@ int kk_register_auth_get(){
static int s_count = 0; static int s_count = 0;
CURL* curl; CURL* curl;
ret = kk_check_config_file(KK_CONFIG_FILE_PATH,&configData); ret = kk_check_config_file(KK_CONFIG_FILE_PATH,&configData);
defaultCon:
if(ret != 0){
defaultFlag = 1;
ret = kk_check_config_file(KK_DEFAULT_CONFIG_FILE_PATH,&configData);
}
if(ret == 0){ if(ret == 0){
ret = _kk_get_auth_dl_host(configData,url); ret = _kk_get_auth_dl_host(configData,url);
if(ret == -2 && defaultFlag == 0){
goto defaultCon;
}
if(ret == 0){ if(ret == 0){
again: again:
s_count++; s_count++;
......
...@@ -10,7 +10,6 @@ static const char* OPT_SEND = "MQTTAsync_sendMessage"; ...@@ -10,7 +10,6 @@ static const char* OPT_SEND = "MQTTAsync_sendMessage";
static const char* OPT_SUB = "MQTTAsync_subscribe"; static const char* OPT_SUB = "MQTTAsync_subscribe";
static const char* OPT_UNSUB = "MQTTAsync_unsubscribe"; static const char* OPT_UNSUB = "MQTTAsync_unsubscribe";
static MQTTAsync s_Client; static MQTTAsync s_Client;
static int s_mqttStop = 0;
static int s_cloudStatus = DEVICE_OFFLINE; static int s_cloudStatus = DEVICE_OFFLINE;
static char *kk_will_message_create(char *ccuid,cJSON*payload) static char *kk_will_message_create(char *ccuid,cJSON*payload)
...@@ -50,7 +49,6 @@ static void connlost(void *context, char *cause) ...@@ -50,7 +49,6 @@ static void connlost(void *context, char *cause)
if(context == NULL || cause == NULL) if(context == NULL || cause == NULL)
{ {
ERROR_PRINT("PARAM ERROR\n"); ERROR_PRINT("PARAM ERROR\n");
s_mqttStop = 1;
s_cloudStatus = DEVICE_OFFLINE; s_cloudStatus = DEVICE_OFFLINE;
kk_write_disconnect_flag(); kk_write_disconnect_flag();
KK_Send_CloudState(s_cloudStatus); KK_Send_CloudState(s_cloudStatus);
...@@ -75,7 +73,7 @@ static void connlost(void *context, char *cause) ...@@ -75,7 +73,7 @@ static void connlost(void *context, char *cause)
cJSON* willPayload = cJSON_CreateObject(); cJSON* willPayload = cJSON_CreateObject();
message = kk_will_message_create(ccuid,willPayload); message = kk_will_message_create(ccuid,willPayload);
conn_opts.keepAliveInterval = 20; conn_opts.keepAliveInterval = 20;
conn_opts.cleansession = 1; conn_opts.cleansession = 0;
will_opts.retained = 0; //retained = 1 时, broker会一直保留消息,这里不需要,使用默认的0就行 will_opts.retained = 0; //retained = 1 时, broker会一直保留消息,这里不需要,使用默认的0就行
will_opts.topicName = topicBuf; will_opts.topicName = topicBuf;
will_opts.message = message; will_opts.message = message;
...@@ -83,7 +81,6 @@ static void connlost(void *context, char *cause) ...@@ -83,7 +81,6 @@ static void connlost(void *context, char *cause)
if ((rc = MQTTAsync_connect(client, &conn_opts)) != MQTTASYNC_SUCCESS) if ((rc = MQTTAsync_connect(client, &conn_opts)) != MQTTASYNC_SUCCESS)
{ {
ERROR_PRINT("Failed to start connect, return code %d\n", rc); ERROR_PRINT("Failed to start connect, return code %d\n", rc);
s_mqttStop = 1;
} }
free(message); free(message);
cJSON_Delete(willPayload); cJSON_Delete(willPayload);
...@@ -92,13 +89,11 @@ static void connlost(void *context, char *cause) ...@@ -92,13 +89,11 @@ static void connlost(void *context, char *cause)
void onDisconnectFailure(void* context, MQTTAsync_failureData* response) void onDisconnectFailure(void* context, MQTTAsync_failureData* response)
{ {
WARNING_PRINT("Disconnect failed\n"); WARNING_PRINT("Disconnect failed\n");
s_mqttStop = 1;
} }
void onDisconnect(void* context, MQTTAsync_successData* response) void onDisconnect(void* context, MQTTAsync_successData* response)
{ {
WARNING_PRINT("Successful disconnection\n"); WARNING_PRINT("Successful disconnection\n");
s_mqttStop = 1;
} }
void onSendFailure(void* context, MQTTAsync_failureData* response) void onSendFailure(void* context, MQTTAsync_failureData* response)
...@@ -136,7 +131,6 @@ void onSend(void* context, MQTTAsync_successData* response) ...@@ -136,7 +131,6 @@ void onSend(void* context, MQTTAsync_successData* response)
extern void KK_reset_sub_flag(void); extern void KK_reset_sub_flag(void);
void onConnectFailure(void* context, MQTTAsync_failureData* response) void onConnectFailure(void* context, MQTTAsync_failureData* response)
{ {
s_mqttStop = 1;
if(response == NULL) if(response == NULL)
{ {
ERROR_PRINT("PARAM ERROR\n"); ERROR_PRINT("PARAM ERROR\n");
...@@ -299,7 +293,7 @@ MQTTAsync KK_MQTT_Connect(void) ...@@ -299,7 +293,7 @@ MQTTAsync KK_MQTT_Connect(void)
//conn_opts.password = PASSWORD; //conn_opts.password = PASSWORD;
conn_opts.username = usrname; conn_opts.username = usrname;
conn_opts.password = token; conn_opts.password = token;
conn_opts.cleansession = 1; conn_opts.cleansession = 0;
conn_opts.onSuccess = onConnect; conn_opts.onSuccess = onConnect;
conn_opts.onFailure = onConnectFailure; conn_opts.onFailure = onConnectFailure;
conn_opts.context = s_Client; conn_opts.context = s_Client;
...@@ -357,7 +351,7 @@ MQTTAsync KK_MQTT_Connect_ex(char *usrname,char*pwd,char*cliendId,char*host,char ...@@ -357,7 +351,7 @@ MQTTAsync KK_MQTT_Connect_ex(char *usrname,char*pwd,char*cliendId,char*host,char
//conn_opts.password = PASSWORD; //conn_opts.password = PASSWORD;
conn_opts.username = usrname; conn_opts.username = usrname;
conn_opts.password = pwd; conn_opts.password = pwd;
conn_opts.cleansession = 1; conn_opts.cleansession = 0;
conn_opts.onSuccess = onConnect; conn_opts.onSuccess = onConnect;
conn_opts.onFailure = onConnectFailure; conn_opts.onFailure = onConnectFailure;
conn_opts.context = s_Client; conn_opts.context = s_Client;
......
...@@ -73,37 +73,50 @@ int kk_alarm_notify_handle(dm_mgr_dev_node_t *node,char *identifier,char *valueB ...@@ -73,37 +73,50 @@ int kk_alarm_notify_handle(dm_mgr_dev_node_t *node,char *identifier,char *valueB
HAL_Get_ccuid(ccuid); HAL_Get_ccuid(ccuid);
kk_property_db_get_value(node->deviceCode,"SensorType",&currentValue); kk_property_db_get_value(node->deviceCode,"SensorType",&currentValue);
INFO_PRINT("------------------------->currentValue:%d\n",currentValue); //INFO_PRINT("------------------------->currentValue:%d\n",currentValue);
INFO_PRINT("------------------------->armingstate:%d\n",atoi(armingstate)); //INFO_PRINT("------------------------->valueBuf:%s\n",valueBuf);
INFO_PRINT("------------------------->valueBuf:%s\n",valueBuf); //INFO_PRINT("------------------------->identifier:%s\n",identifier);
INFO_PRINT("------------------------->identifier:%s\n",identifier);
kk_property_db_get_value(ccuid,KK_TSL_CCU_ARMINGSTATE_IDENTIFIER,armingstate); kk_property_db_get_value(ccuid,KK_TSL_CCU_ARMINGSTATE_IDENTIFIER,armingstate);
if(strcmp(node->productCode,"3064") == 0){//门锁强报警
currentValue = SUB_ARMING_ALL_STATE;
}
cJSON *info = cJSON_CreateObject(); cJSON *info = cJSON_CreateObject();
cJSON_AddStringToObject(info, MSG_TYPE_STR, "/thing/event/alarmNotify");
cJSON_AddStringToObject(info, MSG_DEVICE_CODE_STR, node->deviceCode); cJSON_AddStringToObject(info, MSG_DEVICE_CODE_STR, node->deviceCode);
cJSON_AddStringToObject(info, MSG_PRODUCT_CODE_STR, node->productCode); cJSON_AddStringToObject(info, MSG_PRODUCT_CODE_STR, node->productCode);
char *infff=cJSON_Print(info);
cJSON *payload = cJSON_CreateObject(); cJSON *payload = cJSON_CreateObject();
cJSON_AddStringToObject(payload, "method", "thing.event.alarmNotify");
cJSON_AddStringToObject(payload, "version", "1.0"); cJSON_AddStringToObject(payload, "version", "1.0");
cJSON_AddStringToObject(payload, "identifier", "alarmNotify");
char msgId[64] = {0}; char msgId[64] = {0};
iotx_report_id(msgId); iotx_report_id(msgId);
cJSON_AddStringToObject(payload, "msgId", msgId); cJSON_AddStringToObject(payload, "msgId", msgId);
//char timerStr[16] = {0}; //char timerStr[16] = {0};
//HAL_GetTime_s(timerStr); //HAL_GetTime_s(timerStr);
cJSON_AddNumberToObject(payload, "time", HAL_GetTime_ms()); cJSON_AddNumberToObject(payload, "time", HAL_GetTime_ms());
cJSON *param = cJSON_CreateObject(); cJSON *param = cJSON_CreateObject();
if(strcmp(identifier,"BatteryAlarm") == 0){ if(strcmp(identifier,"BatteryAlarm") == 0){
cJSON_AddStringToObject(param, "LowBatteryState", "1"); if(atoi(valueBuf) == 1){
//needSave = 1; cJSON_AddStringToObject(param, "LowBatteryState", "1");
cJSON_AddStringToObject(info, MSG_TYPE_STR, "/thing/event/BatteryAlarm/post");
cJSON_AddStringToObject(payload, "method", "thing.event.BatteryAlarm.post");
cJSON_AddStringToObject(payload, "identifier", "BatteryAlarm");
}else{
cJSON_Delete(param);
cJSON_Delete(payload);
cJSON_Delete(info);
return 0;
}
}else if(strcmp(identifier,"DismantleState") == 0){ }else if(strcmp(identifier,"DismantleState") == 0){
if(atoi(valueBuf) == 1){ if(atoi(valueBuf) == 1){
cJSON_AddStringToObject(param, "DismantleState", valueBuf); if(strcmp(node->productCode,"3064") == 0){//门锁防拆特殊处理
cJSON_AddStringToObject(param, "DismantleState", valueBuf);
cJSON_AddStringToObject(info, MSG_TYPE_STR, "/thing/event/LockTamperAlarm/post");
cJSON_AddStringToObject(payload, "method", "thing.event.LockTamperAlarm.post");
cJSON_AddStringToObject(payload, "identifier", "LockTamperAlarm");
}else{
cJSON_AddStringToObject(param, "DismantleState", valueBuf);
cJSON_AddStringToObject(info, MSG_TYPE_STR, "/thing/event/alarmNotify");
cJSON_AddStringToObject(payload, "method", "thing.event.alarmNotify");
cJSON_AddStringToObject(payload, "identifier", "alarmNotify");
}
}else{ }else{
cJSON_Delete(param); cJSON_Delete(param);
cJSON_Delete(payload); cJSON_Delete(payload);
...@@ -115,6 +128,9 @@ int kk_alarm_notify_handle(dm_mgr_dev_node_t *node,char *identifier,char *valueB ...@@ -115,6 +128,9 @@ int kk_alarm_notify_handle(dm_mgr_dev_node_t *node,char *identifier,char *valueB
//cJSON_AddStringToObject(param, "CommonAlarmState", valueBuf); //cJSON_AddStringToObject(param, "CommonAlarmState", valueBuf);
// } // }
else{ else{
cJSON_AddStringToObject(info, MSG_TYPE_STR, "/thing/event/alarmNotify");
cJSON_AddStringToObject(payload, "method", "thing.event.alarmNotify");
cJSON_AddStringToObject(payload, "identifier", "alarmNotify");
if(atoi(valueBuf) == 1){ if(atoi(valueBuf) == 1){
cJSON_AddStringToObject(param, "CommonAlarmState", "1"); cJSON_AddStringToObject(param, "CommonAlarmState", "1");
}else{ }else{
...@@ -127,6 +143,7 @@ int kk_alarm_notify_handle(dm_mgr_dev_node_t *node,char *identifier,char *valueB ...@@ -127,6 +143,7 @@ int kk_alarm_notify_handle(dm_mgr_dev_node_t *node,char *identifier,char *valueB
} }
cJSON_AddItemToObject(payload, "params", param); cJSON_AddItemToObject(payload, "params", param);
char *payload11=cJSON_Print(payload); char *payload11=cJSON_Print(payload);
char *infff=cJSON_Print(info);
if(currentValue == SUB_ARMING_ALL_STATE)//24小时警戒 if(currentValue == SUB_ARMING_ALL_STATE)//24小时警戒
{ {
INFO_PRINT("payload11: %s\n",payload11); INFO_PRINT("payload11: %s\n",payload11);
......
...@@ -1910,12 +1910,12 @@ int kk_is_mutiEp_device(const char *deviceCode) ...@@ -1910,12 +1910,12 @@ int kk_is_mutiEp_device(const char *deviceCode)
int res = 0; int res = 0;
int idx = 0; int idx = 0;
kk_tsl_data_t *property = NULL; kk_tsl_data_t *property = NULL;
dm_mgr_dev_node_t *node = NULL; dm_mgr_dev_node_t *node = NULL;
res = dm_mgr_get_device_by_devicecode((char*)deviceCode,&node); res = dm_mgr_get_device_by_devicecode((char*)deviceCode,&node);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
ERROR_PRINT("ERROR [%s][%d] res:%d\n",__FUNCTION__,__LINE__,res); ERROR_PRINT("ERROR [%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
return FAIL_RETURN; return FAIL_RETURN;
} }
for(idx = 0; idx < node->dev_shadow->property_number; idx++){ for(idx = 0; idx < node->dev_shadow->property_number; idx++){
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx); property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
if(property == NULL){ if(property == NULL){
......
...@@ -1288,9 +1288,9 @@ static int kk_service_addScreen_handle(cJSON *info,cJSON *msgId,cJSON *params) ...@@ -1288,9 +1288,9 @@ static int kk_service_addScreen_handle(cJSON *info,cJSON *msgId,cJSON *params)
if(devtype == NULL) return INVALID_PARAMETER; if(devtype == NULL) return INVALID_PARAMETER;
kk_service_addScreen_handle_reply(info,msgId,serialid->valuestring); kk_service_addScreen_handle_reply(info,msgId,serialid->valuestring);
if(strcmp(mac_head,"01:01") == 0){//moore4c mac if(strcmp(mac_head,"01:01") == 0){//moore4c mac
kk_screenDev_insert_db(devtype->valueint,serialid->valuestring,ip->valuestring,&str_mac[6],version->valuestring,""); kk_screenDev_insert_db(devtype->valueint,serialid->valuestring,ip->valuestring,&str_mac[6],version->valuestring,"","MOORE4C");
}else{ }else{
kk_screenDev_insert_db(devtype->valueint,serialid->valuestring,ip->valuestring,str_mac,version->valuestring,""); kk_screenDev_insert_db(devtype->valueint,serialid->valuestring,ip->valuestring,str_mac,version->valuestring,"","MOORE4S");
} }
kk_service_client_online_push(info,msgId,serialid->valuestring); kk_service_client_online_push(info,msgId,serialid->valuestring);
return SUCCESS_RETURN; return SUCCESS_RETURN;
......
...@@ -838,7 +838,41 @@ int kk_indoorAir_db_insert(const char *deviceCode,const char *identifier,kk_tsl_ ...@@ -838,7 +838,41 @@ int kk_indoorAir_db_insert(const char *deviceCode,const char *identifier,kk_tsl_
_kk_property_db_unlock(); _kk_property_db_unlock();
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
/************************************************************
*功能描述: 获取空调内机属性值
*输入参数: deviceCode:设备deviceCode
identifier:属性名称
*输出参数: value:属性值,返回的是字串
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int kk_indoorair_property_db_get_value_directly(const char *deviceCode,const char *identifier,char* value,int ep)
{
char *sqlCmd = NULL;
//int rc = 0;
//char *zErrMsg = 0;
int epNum = 0;
sqlite3_stmt *stmt;
char *valueStr = "";
kk_property_db_ctx_t *ctx = _kk_property_db_get_ctx();
_kk_property_db_lock();
sqlCmd = sqlite3_mprintf("select * from indoorAirProperties WHERE deviceCode= '%s' and identifier = '%s'",deviceCode,identifier);
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
valueStr = (char*)sqlite3_column_text(stmt, DB_INDOORAIR_VALUE);
epNum = sqlite3_column_int(stmt, DB_INDOORAIR_EPNUM);
if(ep == epNum){
memcpy(value,valueStr, strlen(valueStr));
}
}
sqlite3_free(sqlCmd);
_kk_property_db_unlock();
sqlite3_finalize(stmt);
return SUCCESS_RETURN;
}
/************************************************************ /************************************************************
*功能描述: 查询空调内机数量 *功能描述: 查询空调内机数量
*输入参数: deviceCode:设备deviceCode *输入参数: deviceCode:设备deviceCode
...@@ -1062,11 +1096,11 @@ int kk_property_db_get_value(const char *deviceCode,const char *identifier,void* ...@@ -1062,11 +1096,11 @@ int kk_property_db_get_value(const char *deviceCode,const char *identifier,void*
*(int*)value = value_int; *(int*)value = value_int;
} }
else if(valueType == KK_TSL_DATA_TYPE_FLOAT){ else if(valueType == KK_TSL_DATA_TYPE_FLOAT){
float value_float = atoi(valueStr); float value_float = atof(valueStr);
*(float*)value = value_float; *(float*)value = value_float;
} }
else if(valueType == KK_TSL_DATA_TYPE_DOUBLE){ else if(valueType == KK_TSL_DATA_TYPE_DOUBLE){
double value_double = atoi(valueStr); double value_double = atof(valueStr);
*(double*)value = value_double; *(double*)value = value_double;
} }
else{ else{
......
...@@ -90,5 +90,6 @@ int kk_subFreshAir_get_online(const char *deviceCode,int ep); ...@@ -90,5 +90,6 @@ int kk_subFreshAir_get_online(const char *deviceCode,int ep);
int kk_indoorAir_db_update_online(const char *deviceCode,int online,int epNum); int kk_indoorAir_db_update_online(const char *deviceCode,int online,int epNum);
int kk_subFreshAir_db_update_online(const char *deviceCode,int online,int epNum); int kk_subFreshAir_db_update_online(const char *deviceCode,int online,int epNum);
int kk_subAirSwitch_db_update_online(const char *deviceCode,int online,int epNum); int kk_subAirSwitch_db_update_online(const char *deviceCode,int online,int epNum);
int kk_indoorair_property_db_get_value_directly(const char *deviceCode,const char *identifier,char* value,int ep);
#endif #endif
...@@ -311,6 +311,29 @@ int kk_LockUser_insert_db(char *keyId,char *keyType,char *keyRole,char *keyName, ...@@ -311,6 +311,29 @@ int kk_LockUser_insert_db(char *keyId,char *keyType,char *keyRole,char *keyName,
_kk_subDb_unlock(); _kk_subDb_unlock();
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
int kk_delete_LockUser_info_byId(const char *id)
{
const char *deleteCmd = "delete from LockUserInfo where keyId = '%s';";
char *sqlCmd = NULL;
int rc = 0;
char *zErrMsg = 0;
kk_subDb_ctx_t *ctx = _kk_subDb_get_ctx();
_kk_subDb_lock();
sqlCmd = sqlite3_mprintf(deleteCmd,id);
INFO_PRINT("Table delete data sqlCmd:%s\n",sqlCmd);
rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( rc != SQLITE_OK ){
ERROR_PRINT("SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
//INFO_PRINT("Table delete data successfully\n");
}
sqlite3_free(sqlCmd);
_kk_subDb_unlock();
return SUCCESS_RETURN;
}
/************************************************************ /************************************************************
*功能描述:获取屏类列表 *功能描述:获取屏类列表
*输入参数:deviceCode:设备deviceCode *输入参数:deviceCode:设备deviceCode
...@@ -820,6 +843,20 @@ int kk_indoor_air_action_add(char *propertyValue,char* deviceCode,int delay,char ...@@ -820,6 +843,20 @@ int kk_indoor_air_action_add(char *propertyValue,char* deviceCode,int delay,char
if (json == NULL) { if (json == NULL) {
return -1; return -1;
} }
cJSON* WorkMode = cJSON_GetObjectItem(json, "WorkMode");
if(WorkMode == NULL){ cJSON_Delete(json);return -1;}
memset(data,0x0,sizeof(data));
if(WorkMode->type == cJSON_String){
memcpy(data,WorkMode->valuestring,strlen(WorkMode->valuestring));
}else{
sprintf(data,"%d",WorkMode->valueint);
}
if(mutiDev){
_kk_indoor_air_info_handle(deviceCode,"WorkMode_1",data,epnum,delay,gwDeviceCode,sceneId,type,0);
}else{
_kk_indoor_air_info_handle(deviceCode,"WorkMode",data,epnum,delay,gwDeviceCode,sceneId,type,0);
}
cJSON* Temperature = cJSON_GetObjectItem(json, "Temperature"); cJSON* Temperature = cJSON_GetObjectItem(json, "Temperature");
if(Temperature == NULL) { cJSON_Delete(json);return -1;} if(Temperature == NULL) { cJSON_Delete(json);return -1;}
memset(data,0x0,sizeof(data)); memset(data,0x0,sizeof(data));
...@@ -848,21 +885,6 @@ int kk_indoor_air_action_add(char *propertyValue,char* deviceCode,int delay,char ...@@ -848,21 +885,6 @@ int kk_indoor_air_action_add(char *propertyValue,char* deviceCode,int delay,char
_kk_indoor_air_info_handle(deviceCode,"WindSpeed",data,epnum,delay,gwDeviceCode,sceneId,type,0); _kk_indoor_air_info_handle(deviceCode,"WindSpeed",data,epnum,delay,gwDeviceCode,sceneId,type,0);
} }
cJSON* WorkMode = cJSON_GetObjectItem(json, "WorkMode");
if(WorkMode == NULL){ cJSON_Delete(json);return -1;}
memset(data,0x0,sizeof(data));
if(WorkMode->type == cJSON_String){
memcpy(data,WorkMode->valuestring,strlen(WorkMode->valuestring));
}else{
sprintf(data,"%d",WorkMode->valueint);
}
if(mutiDev){
_kk_indoor_air_info_handle(deviceCode,"WorkMode_1",data,epnum,delay,gwDeviceCode,sceneId,type,0);
}else{
_kk_indoor_air_info_handle(deviceCode,"WorkMode",data,epnum,delay,gwDeviceCode,sceneId,type,0);
}
cJSON_Delete(json); cJSON_Delete(json);
return 0; return 0;
} }
...@@ -1265,7 +1287,7 @@ int kk_screenDev_update(int devType,char *serialId, \ ...@@ -1265,7 +1287,7 @@ int kk_screenDev_update(int devType,char *serialId, \
*其他说明: *其他说明:
*************************************************************/ *************************************************************/
int kk_screenDev_insert_db(int devType,char *serialId, \ int kk_screenDev_insert_db(int devType,char *serialId, \
char *ip,char *mac,char *version,char *expand) char *ip,char *mac,char *version,char *expand,char *name)
{ {
const char *insertCmd = "insert into ScreenDeviceInfo (isOffline,type,serialId,deviceIp,deviceName,mac,version,roomId,roomName,expand) \ const char *insertCmd = "insert into ScreenDeviceInfo (isOffline,type,serialId,deviceIp,deviceName,mac,version,roomId,roomName,expand) \
values ('%d','%d','%s','%s','%s','%s','%s','%s','%s','%s');"; values ('%d','%d','%s','%s','%s','%s','%s','%s','%s','%s');";
...@@ -1281,11 +1303,7 @@ int kk_screenDev_insert_db(int devType,char *serialId, \ ...@@ -1281,11 +1303,7 @@ int kk_screenDev_insert_db(int devType,char *serialId, \
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
_kk_subDb_lock(); _kk_subDb_lock();
#ifdef CONFIG_A133_PLATFORM sqlCmd = sqlite3_mprintf(insertCmd,1,devType,serialId,ip,name,mac,version,"","",expand);
sqlCmd = sqlite3_mprintf(insertCmd,1,devType,serialId,ip,"MOOR4S",mac,version,"","",expand);
#else
sqlCmd = sqlite3_mprintf(insertCmd,1,devType,serialId,ip,"MOOR4C",mac,version,"","",expand);
#endif
rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg); rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( rc != SQLITE_OK ){ if( rc != SQLITE_OK ){
......
...@@ -43,7 +43,7 @@ int kk_subDev_getSensors_reply(SensorType_t*list); ...@@ -43,7 +43,7 @@ int kk_subDev_getSensors_reply(SensorType_t*list);
int kk_load_subDevice(void); int kk_load_subDevice(void);
int kk_subDev_check_auth(int devType); int kk_subDev_check_auth(int devType);
int kk_screenDev_insert_db(int devType,char *serialId, \ int kk_screenDev_insert_db(int devType,char *serialId, \
char *ip,char *mac,char *version,char *expand); char *ip,char *mac,char *version,char *expand,char *name);
int kk_screenDev_update_room(char *serialId,char *roomid,char *roomname,char* name); int kk_screenDev_update_room(char *serialId,char *roomid,char *roomname,char* name);
int kk_screenDev_delete_by_serialId(char *serialId); int kk_screenDev_delete_by_serialId(char *serialId);
int kk_get_screenDev_list(ScreenDevInfo_t*list); int kk_get_screenDev_list(ScreenDevInfo_t*list);
...@@ -55,6 +55,7 @@ int kk_subDev_find_fatherDeviceCode(const char *deviceCode,char *fatherDeviceCod ...@@ -55,6 +55,7 @@ int kk_subDev_find_fatherDeviceCode(const char *deviceCode,char *fatherDeviceCod
int kk_LockUser_insert_db(char *keyId,char *keyType,char*keyRole,char *keyName,char* deviceCode); int kk_LockUser_insert_db(char *keyId,char *keyType,char*keyRole,char *keyName,char* deviceCode);
int kk_get_LockUser_list(LockKeyInfo_t *list,const char *deviceCode); int kk_get_LockUser_list(LockKeyInfo_t *list,const char *deviceCode);
int kk_delete_LockUser_info(const char *deviceCode); int kk_delete_LockUser_info(const char *deviceCode);
int kk_delete_LockUser_info_byId(const char *id);
enum{ enum{
DB_SUB_IDX = 0, DB_SUB_IDX = 0,
DB_SUB_ONLINE, DB_SUB_ONLINE,
......
...@@ -326,13 +326,11 @@ static int kk_property_set_data_check(cJSON * payload,const char *deviceCode){ ...@@ -326,13 +326,11 @@ static int kk_property_set_data_check(cJSON * payload,const char *deviceCode){
}else{ }else{
epNumInt = 1; epNumInt = 1;
} }
//printf("----------------->epNumInt:%d\n",epNumInt);
for(idx = 0; idx < node->dev_shadow->property_number; idx++){ for(idx = 0; idx < node->dev_shadow->property_number; idx++){
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx); property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
if(property == NULL){ if(property == NULL){
continue; continue;
} }
//printf("----------------->property->identifier:%s\n",property->identifier);
memset(propertiesTmp,0x0,sizeof(propertiesTmp)); memset(propertiesTmp,0x0,sizeof(propertiesTmp));
memcpy(propertiesTmp,property->identifier,strlen(property->identifier)); memcpy(propertiesTmp,property->identifier,strlen(property->identifier));
split(propertiesTmp,"_",propertiesbuf,&num); split(propertiesTmp,"_",propertiesbuf,&num);
...@@ -996,8 +994,9 @@ void mid_cb(void* data, int len){ ...@@ -996,8 +994,9 @@ void mid_cb(void* data, int len){
cJSON_Delete(json); cJSON_Delete(json);
return; return;
} }
#if 0
if(strcmp(gw_node->productType,KK_DM_AIR_SWITCH_GATEWAY_TYPE) == 0){ if(strcmp(gw_node->productType,KK_DM_AIR_SWITCH_GATEWAY_TYPE) == 0){
res = _kk_handle_airswitch_property(gw_node->fatherDeviceCode,info_root,payload);//空开epnum 传的是数组,无语 res = _kk_handle_airswitch_property(gw_node->fatherDeviceCode,info_root,payload);
if(res != 0){ if(res != 0){
cJSON * rootData=cJSON_CreateObject(); cJSON * rootData=cJSON_CreateObject();
char *info_rootS=cJSON_Print(info_root); char *info_rootS=cJSON_Print(info_root);
...@@ -1011,7 +1010,9 @@ void mid_cb(void* data, int len){ ...@@ -1011,7 +1010,9 @@ void mid_cb(void* data, int len){
free(payloadS); free(payloadS);
free(pnewout); free(pnewout);
} }
}else{ }else
#endif
{
cJSON * rootData=cJSON_CreateObject(); cJSON * rootData=cJSON_CreateObject();
char *info_rootS=cJSON_Print(info_root); char *info_rootS=cJSON_Print(info_root);
char *payloadS = cJSON_Print(payload); char *payloadS = cJSON_Print(payload);
...@@ -1093,7 +1094,67 @@ void gw2mid_cb(void* data, int len, char* chalMark){ ...@@ -1093,7 +1094,67 @@ void gw2mid_cb(void* data, int len, char* chalMark){
mid2p_cb(data,len,chalMark); mid2p_cb(data,len,chalMark);
} }
} }
static int _kk_subDevice_property_single_save(cJSON *params,char *deviceCode,int type)
{
int res = 0;
int epNumInt = 0;
dm_mgr_dev_node_t *node = NULL;
kk_tsl_data_t *property = NULL;
cJSON *propertyItem = NULL;
int idx = 0;
res = dm_mgr_get_device_by_devicecode(deviceCode,&node);
if (res < SUCCESS_RETURN) {
return FAIL_RETURN;
}
cJSON *epNum = cJSON_GetObjectItem(params, "epNum");
if(epNum == NULL) return FAIL_RETURN;
if(epNum->type == cJSON_Number){
epNumInt = epNum->valueint;
}else if(epNum->type == cJSON_String){
epNumInt = atoi(epNum->valuestring);
}
for(idx = 0; idx < node->dev_shadow->property_number; idx++){
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
if(property == NULL){
continue;
}
propertyItem = cJSON_GetObjectItem(params, property->identifier);
if(propertyItem != NULL){
if(property->data_value.type == KK_TSL_DATA_TYPE_INT ||property->data_value.type == KK_TSL_DATA_TYPE_ENUM
||property->data_value.type == KK_TSL_DATA_TYPE_BOOL){
char valBuf[16] = {0};
int value = propertyItem->valueint;
sprintf(valBuf,"%d",value);
if(type == 0){
kk_indoorAir_db_update_value(deviceCode,property->identifier,valBuf,epNumInt);
}else if(type == 1){
kk_subAirSwitch_db_update_value(deviceCode,property->identifier,valBuf,epNumInt);
}else if(type == 2){
kk_subFreshAir_db_update_value(deviceCode,property->identifier,valBuf,epNumInt);
}
}else if(property->data_value.type == KK_TSL_DATA_TYPE_FLOAT || property->data_value.type == KK_TSL_DATA_TYPE_DOUBLE){
char valBuf[16] = {0};
sprintf(valBuf,"%f",propertyItem->valuedouble);
if(type == 0){
kk_indoorAir_db_update_value(deviceCode,property->identifier,valBuf,epNumInt);
}else if(type == 1){
kk_subAirSwitch_db_update_value(deviceCode,property->identifier,valBuf,epNumInt);
}else if(type == 2){
kk_subFreshAir_db_update_value(deviceCode,property->identifier,valBuf,epNumInt);
}
}else if(property->data_value.type == KK_TSL_DATA_TYPE_TEXT ){
if(type == 0){
kk_indoorAir_db_update_value(deviceCode,property->identifier,propertyItem->valuestring,epNumInt);
}else if(type == 1){
kk_subAirSwitch_db_update_value(deviceCode,property->identifier,propertyItem->valuestring,epNumInt);
}else if(type == 2){
kk_subFreshAir_db_update_value(deviceCode,property->identifier,propertyItem->valuestring,epNumInt);
}
}
}
}
return 0;
}
static int kk_subDevice_property_save(cJSON *payload,char *deviceCode,int type) static int kk_subDevice_property_save(cJSON *payload,char *deviceCode,int type)
{ {
dm_mgr_dev_node_t *node = NULL; dm_mgr_dev_node_t *node = NULL;
...@@ -1106,7 +1167,8 @@ static int kk_subDevice_property_save(cJSON *payload,char *deviceCode,int type) ...@@ -1106,7 +1167,8 @@ static int kk_subDevice_property_save(cJSON *payload,char *deviceCode,int type)
if(params == NULL) return FAIL_RETURN; if(params == NULL) return FAIL_RETURN;
cJSON *eps = cJSON_GetObjectItem(params, "eps"); cJSON *eps = cJSON_GetObjectItem(params, "eps");
if(eps == NULL || eps->type != cJSON_Array){ if(eps == NULL || eps->type != cJSON_Array){
return FAIL_RETURN; //return FAIL_RETURN;
return _kk_subDevice_property_single_save(params,deviceCode,type);
} }
res = dm_mgr_get_device_by_devicecode(deviceCode,&node); res = dm_mgr_get_device_by_devicecode(deviceCode,&node);
if (res < SUCCESS_RETURN) { if (res < SUCCESS_RETURN) {
...@@ -1174,6 +1236,15 @@ static int kk_subDevice_property_save(cJSON *payload,char *deviceCode,int type) ...@@ -1174,6 +1236,15 @@ static int kk_subDevice_property_save(cJSON *payload,char *deviceCode,int type)
/*type : 0,air condition gw;1,air switch gw;2,fresh air switch*/ /*type : 0,air condition gw;1,air switch gw;2,fresh air switch*/
static int kk_subDevice_property_handle(cJSON *info,cJSON *payload,char *deviceCode,int type) static int kk_subDevice_property_handle(cJSON *info,cJSON *payload,char *deviceCode,int type)
{ {
int snapshot = 0;
cJSON * jsonPay = cJSON_GetObjectItem(payload, MSG_PARAMS_STR);
if(jsonPay == NULL){
return -1;
}
cJSON *eps = cJSON_GetObjectItem(jsonPay, "eps");
if(eps != NULL){
snapshot = 1;
}
kk_subDevice_property_save(payload,deviceCode,type); kk_subDevice_property_save(payload,deviceCode,type);
cJSON_AddStringToObject(payload, MSG_DEVICE_CODE_STR, deviceCode); cJSON_AddStringToObject(payload, MSG_DEVICE_CODE_STR, deviceCode);
char *payload11=cJSON_Print(payload); char *payload11=cJSON_Print(payload);
...@@ -1181,6 +1252,9 @@ static int kk_subDevice_property_handle(cJSON *info,cJSON *payload,char *deviceC ...@@ -1181,6 +1252,9 @@ static int kk_subDevice_property_handle(cJSON *info,cJSON *payload,char *deviceC
kk_sendData2app(infff,payload11,0); kk_sendData2app(infff,payload11,0);
free(payload11); free(payload11);
free(infff); free(infff);
if(!snapshot){//快照信息不处理
kk_scene_iftt_check(deviceCode,jsonPay);
}
return 0; return 0;
} }
static int _kk_subDevice_online_to_app(cJSON *info,cJSON *payload) static int _kk_subDevice_online_to_app(cJSON *info,cJSON *payload)
...@@ -1452,14 +1526,14 @@ void kk_platMsg_handle(void* data, char* chalMark){ ...@@ -1452,14 +1526,14 @@ void kk_platMsg_handle(void* data, char* chalMark){
} }
else{ else{
/*插座类设备保存功率历史记录*/ /*插座类设备保存功率历史记录*/
if(strcmp(search_node->productType ,"outlet") == 0){ //if(strcmp(search_node->productType ,"outlet") == 0){
cJSON *power = cJSON_GetObjectItem(jsonPay,"Power"); //cJSON *power = cJSON_GetObjectItem(jsonPay,"Power");
if(power != NULL){ //if(power != NULL){
char buf[16] = {0}; //char buf[16] = {0};
sprintf(buf,"%f",power->valuedouble); //sprintf(buf,"%f",power->valuedouble);
kk_history_insert_Outlet_info(info_dcode->valuestring,buf,"",HAL_GetTime()); //kk_history_insert_Outlet_info(info_dcode->valuestring,buf,"",HAL_GetTime());
} //}
} //}
char* outstr = cJSON_Print(payload); char* outstr = cJSON_Print(payload);
kk_tsl_property_set_by_shadow(search_node->dev_shadow, outstr, strlen(outstr)+1); kk_tsl_property_set_by_shadow(search_node->dev_shadow, outstr, strlen(outstr)+1);
proCode = cJSON_GetObjectItem(info, MSG_PRODUCT_CODE_STR); proCode = cJSON_GetObjectItem(info, MSG_PRODUCT_CODE_STR);
...@@ -1507,7 +1581,9 @@ void kk_platMsg_handle(void* data, char* chalMark){ ...@@ -1507,7 +1581,9 @@ void kk_platMsg_handle(void* data, char* chalMark){
dm_mgr_set_dev_onoffline(node,0); dm_mgr_set_dev_onoffline(node,0);
} }
/*如果是传感器类设备,事件上报的同时需要记录数据到数据库*/ /*如果是传感器类设备,事件上报的同时需要记录数据到数据库*/
if(strcmp(node->productType ,"sensor") == 0){ if(strcmp(node->productType ,"sensor" ) == 0 ||
strcmp(node->productType ,"Doorlock" ) == 0 ||
strcmp(node->productType ,"siren" ) == 0){
sensorDev = 1; sensorDev = 1;
} }
if(strcmp(msgType->valuestring, "/thing/event/SceneRecall/post") == 0){ if(strcmp(msgType->valuestring, "/thing/event/SceneRecall/post") == 0){
...@@ -1520,7 +1596,7 @@ void kk_platMsg_handle(void* data, char* chalMark){ ...@@ -1520,7 +1596,7 @@ void kk_platMsg_handle(void* data, char* chalMark){
sprintf(btnId,"%d",buttonId->valueint); sprintf(btnId,"%d",buttonId->valueint);
kk_scene_execute_quickpanel(btnId,info_dcode->valuestring); kk_scene_execute_quickpanel(btnId,info_dcode->valuestring);
} }
INFO_PRINT("-------------------kk_platMsg_handle event post enters \n"); INFO_PRINT("-------------------kk_platMsg_handle event post enters:%s \n",msgType->valuestring);
for(idx = 0; idx < node->dev_shadow->event_number; idx++){ for(idx = 0; idx < node->dev_shadow->event_number; idx++){
eventItem = node->dev_shadow->events + idx; eventItem = node->dev_shadow->events + idx;
if(eventItem != NULL){ if(eventItem != NULL){
...@@ -1572,7 +1648,9 @@ void kk_platMsg_handle(void* data, char* chalMark){ ...@@ -1572,7 +1648,9 @@ void kk_platMsg_handle(void* data, char* chalMark){
} }
if(pack==0){ if(pack==0){
INFO_PRINT("kk_platMsg_handle data: event post,eventItem->identifier:%s\n",eventItem->identifier); INFO_PRINT("kk_platMsg_handle data: event post,eventItem->identifier:%s\n",eventItem->identifier);
if(strcmp(eventItem->identifier,"TamperAlarm") != 0){//TamperAlarm不需要上报,否则APP显示会有问题 if(strcmp(eventItem->identifier,"TamperAlarm") == 0 || strcmp(eventItem->identifier,"sirenAlarm") == 0){//TamperAlarm不需要上报,否则APP显示会有问题
}else{
dm_msg_thing_event_post(info_dcode->valuestring,eventItem->identifier,NULL); dm_msg_thing_event_post(info_dcode->valuestring,eventItem->identifier,NULL);
} }
kk_scene_iftt_check(info_dcode->valuestring,jsonPay); kk_scene_iftt_check(info_dcode->valuestring,jsonPay);
...@@ -1598,6 +1676,13 @@ void kk_platMsg_handle(void* data, char* chalMark){ ...@@ -1598,6 +1676,13 @@ void kk_platMsg_handle(void* data, char* chalMark){
kk_LockUser_insert_db(keyId->valuestring,KeyTypeBuf,KeyRoleBuf,"",info_dcode->valuestring); kk_LockUser_insert_db(keyId->valuestring,KeyTypeBuf,KeyRoleBuf,"",info_dcode->valuestring);
} }
} }
if(strcmp(eventItem->identifier,"KeyDeletedNotification") == 0)
{
cJSON * keyId = cJSON_GetObjectItem(jsonPay, "KeyID");
if(keyId != NULL){
kk_delete_LockUser_info_byId(keyId->valuestring);
}
}
if(strcmp(eventItem->identifier,"LockOpenNotification") == 0){ if(strcmp(eventItem->identifier,"LockOpenNotification") == 0){
kk_scene_iftt_check(info_dcode->valuestring,jsonPay); kk_scene_iftt_check(info_dcode->valuestring,jsonPay);
} }
...@@ -1605,16 +1690,11 @@ void kk_platMsg_handle(void* data, char* chalMark){ ...@@ -1605,16 +1690,11 @@ void kk_platMsg_handle(void* data, char* chalMark){
} }
else if(strcmp(eventItem->identifier,MSG_PROPERTY_STR) != 0 && else if(strcmp(eventItem->identifier,MSG_PROPERTY_STR) != 0 &&
eventItem->output_data_number == 0){ eventItem->output_data_number == 0){
itemStr = cJSON_GetObjectItem(jsonPay, eventItem->identifier); if(strcmp(eventItem->identifier,"DoorBell") != 0){//门铃事件不处理;
if(itemStr != NULL){
if(sensorDev){
//kk_history_insert_sensor_info(info_dcode->valuestring,eventItem->identifier,"",HAL_GetTime());
}
//kk_tsl_set_value(kk_tsl_set_event_output_value,dev_shadow,eventItem->identifier,&itemStr->valueint,NULL);
dm_msg_thing_event_post(info_dcode->valuestring,eventItem->identifier,NULL); dm_msg_thing_event_post(info_dcode->valuestring,eventItem->identifier,NULL);
} }
} }
} }
} }
} }
......
#include <stdio.h>
#include "sqlite3.h"
#include "kk_log.h"
#include "kk_hal.h"
#include "kk_product.h"
#include "kk_tsl_common.h"
#include "kk_tsl_api.h"
#include "kk_dm_api.h"
#include "kk_dm_msg.h"
#include "kk_dm_mng.h"
#include "kk_property_db.h"
#include "kk_mutictrl_handle.h"
#include "kk_scene_handle.h"
static int _kk_check_virtual_device(char *sceneId)
{
int res = 0;
char *sqlCmd = NULL;
char *pdeviceCode = NULL;
dm_mgr_dev_node_t *node = NULL;
sqlite3_stmt *stmt;
kk_scene_ctx_t *ctx = _kk_scene_get_ctx();
sqlCmd = sqlite3_mprintf("select * from SceneActionInfo WHERE sceneId= '%s' and type = '%s'",sceneId,"action/thing/group");//actice判断设备是否移入待分配
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
pdeviceCode = (char*)sqlite3_column_text(stmt,DB_SCENEACTION_DEVICECODE);
res = dm_mgr_get_device_by_devicecode((char*)pdeviceCode, &node);
if(strcmp(node->productCode,"5004") == 0){
sqlite3_free(sqlCmd);
sqlite3_finalize(stmt);
return 1;
}
}
sqlite3_free(sqlCmd);
sqlite3_finalize(stmt);
return 0;
}
int _kk_virtual_mutictrl_ctrl(char *sceneId,int val,char *deviceCode,int ep)
{
char *sqlCmd = NULL;
sqlite3_stmt *stmt;
char *pdeviceCode = NULL;
int res = 0;
int epNum = 0;
dm_mgr_dev_node_t *node = NULL;
kk_scene_ctx_t *ctx = _kk_scene_get_ctx();
if(_kk_check_virtual_device(sceneId) == 0){
return 0;
}
sqlCmd = sqlite3_mprintf("select * from SceneActionInfo WHERE sceneId= '%s' and type = '%s'",sceneId,"action/thing/group");//actice判断设备是否移入待分配
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
pdeviceCode = (char*)sqlite3_column_text(stmt,DB_SCENEACTION_DEVICECODE);
epNum = sqlite3_column_int(stmt, DB_SCENEACTION_EPNUM);
if(strcmp(pdeviceCode,deviceCode) == 0 && ep == epNum){
continue;
}
res = dm_mgr_get_device_by_devicecode((char*)pdeviceCode, &node);
cJSON *param = cJSON_CreateObject();
if(kk_is_mutiEp_device(pdeviceCode) == 1){
if(epNum == 1){
cJSON_AddNumberToObject(param, "PowerSwitch_1", val);
}else if(epNum == 2){
cJSON_AddNumberToObject(param, "PowerSwitch_2", val);
}else if(epNum == 3){
cJSON_AddNumberToObject(param, "PowerSwitch_3", val);
}else if(epNum == 4){
cJSON_AddNumberToObject(param, "PowerSwitch_4", val);
}else{
cJSON_Delete(param);
continue;
}
}else{
cJSON_AddNumberToObject(param, "PowerSwitch", val);
}
char *paramstr=cJSON_Print(param);
kk_msg_execute_property_set(node->productCode,node->deviceCode,paramstr,node->fatherDeviceCode);
free(paramstr);
cJSON_Delete(param);
}
sqlite3_free(sqlCmd);
sqlite3_finalize(stmt);
return SUCCESS_RETURN;
}
void split(char *src,const char *separator,char **dest,int *num);
int kk_virtual_mutictrl_check(const char*deviceCode,cJSON *param)
{
char *sqlCmd = NULL;
sqlite3_stmt *stmt;
char *type = NULL;
char *sceneId = NULL;
int res = 0,idx = 0;
dm_mgr_dev_node_t *node = NULL;
kk_tsl_data_t *property = NULL;
cJSON *propertyItem = NULL;
int value = -1;
char scene_id_bak[64][16] = {0};
int i = 0,count = 0;
int repeat = 0;
int ep = 0,epNum = 0;
char *propertiesbuf[64] = {0};
char propertiesTmp[64] = {0};
int num = 0;
kk_scene_ctx_t *ctx = _kk_scene_get_ctx();
res = dm_mgr_get_device_by_devicecode((char*)deviceCode, &node);
for(idx = 0; idx < node->dev_shadow->property_number; idx++){
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
if(property == NULL || strstr(property->identifier,"PowerSwitch") == NULL){
continue;
}
propertyItem = cJSON_GetObjectItem(param, property->identifier);
if(propertyItem != NULL){
if(strstr(property->identifier,"_") != NULL){
memset(propertiesTmp,0x0,sizeof(propertiesTmp));
memcpy(propertiesTmp,property->identifier,strlen(property->identifier));
split(propertiesTmp,"_",propertiesbuf,&num);
if(num == 2){
ep = atoi(propertiesbuf[1]);
}else{
ep = 1;
}
}else{
ep = 1;
}
value = propertyItem->valueint;
break;
}
}
if(value == -1){
return FAIL_RETURN;
}
sqlCmd = sqlite3_mprintf("select * from SceneActionInfo WHERE deviceCode= '%s' and active = '%d'",deviceCode,1);//actice判断设备是否移入待分配
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
repeat = 0;
type = (char*)sqlite3_column_text(stmt,DB_SCENEACTION_TYPE);
epNum = sqlite3_column_int(stmt, DB_SCENEACTION_EPNUM);
if(strcmp(type,"action/thing/group") != 0 || epNum != ep){
continue;
}
sceneId = (char*)sqlite3_column_text(stmt,DB_SCENEACTION_SCENEID);
for(i = 0; i < count; i++){//检测同个设备在同个场景中设置不同的动作,只需rebuild一次
if(strcmp(scene_id_bak[i],sceneId) == 0){
repeat = 1;
break;
}
}
if(repeat){
continue;
}
_kk_virtual_mutictrl_ctrl(sceneId,value,(char*)deviceCode,ep);
if(count < 64){
memcpy(scene_id_bak[count],sceneId,strlen(sceneId));
count++;
}
}
sqlite3_free(sqlCmd);
sqlite3_finalize(stmt);
return SUCCESS_RETURN;
}
#if 1
char * g_manualMutiCtrlDev[] =
{
(char *){"3062"},
// (char *){"3031"},
// (char *){"3033"},
// (char *){"3034"},
// (char *){"3035"},
// (char *){"3036"},
// (char *){"3095"},
// (char *){"3098"},
(char *){"5004"},
(char *){"3028"},
};
static int _kk_check_manualMutiCtrlDev(const char* deviceCode)
{
int i = 0,num = 0;
dm_mgr_dev_node_t *node = NULL;
num = sizeof(g_manualMutiCtrlDev)/sizeof(char *);
dm_mgr_get_device_by_devicecode((char*)deviceCode, &node);
for(i =0; i < num; i++){
if(strcmp(node->productCode,g_manualMutiCtrlDev[i]) == 0)
{
return 1;
}
}
return 0;
}
static int _kk_get_MutiCtrl_sceneId(char *deviceCode,char *sceneId,int epNum)
{
char *type = NULL;
char *sqlCmd = NULL;
char *psceneId = NULL;
sqlite3_stmt *stmt;
int ep = 0;
int exsit = 0;
kk_scene_ctx_t *ctx = _kk_scene_get_ctx();
sqlCmd = sqlite3_mprintf("select * from SceneActionInfo WHERE deviceCode= '%s' and active = '%d'",deviceCode,1);//actice判断设备是否移入待分配
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
type = (char*)sqlite3_column_text(stmt,DB_SCENEACTION_TYPE);
ep = sqlite3_column_int(stmt, DB_SCENEACTION_EPNUM);
if(strcmp(type,"action/thing/group") != 0 || epNum != ep){
continue;
}
psceneId = (char*)sqlite3_column_text(stmt,DB_SCENEACTION_SCENEID);
memcpy(sceneId,psceneId,strlen(psceneId));
exsit = 1;
break;
}
sqlite3_free(sqlCmd);
sqlite3_finalize(stmt);
if(exsit){
return 0;
}
return -1;
}
static int _kk_manual_mutictrl_set(cJSON *param,char *setDeviceCode,int ep,char* srcDeviceCode,int isMutiEp)
{
int res = 0,idx = 0;
char valueStr[32] = {0};
char oldvalueStr[32] = {0};
char newIdentifier[64] = {0};
dm_mgr_dev_node_t *node = NULL;
dm_mgr_dev_node_t *setDevnode = NULL;
kk_tsl_data_t *property = NULL;
int num = 0;
char epStr[4] = {0};
int offflag = 0;
cJSON *propertyItem = NULL;
res = dm_mgr_get_device_by_devicecode((char*)srcDeviceCode, &node);
res = dm_mgr_get_device_by_devicecode((char*)setDeviceCode, &setDevnode);
for(idx = 0; idx < node->dev_shadow->property_number; idx++){
offflag = 0;
memset(valueStr,0x0,sizeof(valueStr));
memset(oldvalueStr,0x0,sizeof(oldvalueStr));
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
propertyItem = cJSON_GetObjectItem(param, property->identifier);
if(propertyItem != NULL){
if(strstr(property->identifier,"CurrentTemperature") != NULL||
strstr(property->identifier,"TimingOffTime") != NULL||
strstr(property->identifier,"Brightness") != NULL){
continue;
}
if(propertyItem->type == cJSON_Number){
if(property->data_value.type == KK_TSL_DATA_TYPE_INT ||
property->data_value.type == KK_TSL_DATA_TYPE_ENUM||
property->data_value.type == KK_TSL_DATA_TYPE_BOOL){
sprintf(valueStr,"%d",propertyItem->valueint);
}else{
sprintf(valueStr,"%f",propertyItem->valuedouble);
}
}else if(propertyItem->type == cJSON_String){
memcpy(valueStr,propertyItem->valuestring,strlen(propertyItem->valuestring));
}
char *propertiesbuf[64] = {0};
char propertiesTmp[64] = {0};
memset(propertiesTmp,0x0,sizeof(propertiesTmp));
memcpy(propertiesTmp,property->identifier,strlen(property->identifier));
if(isMutiEp){
split(propertiesTmp,"_",propertiesbuf,&num);
}
if(kk_is_mutiEp_device(setDeviceCode) == 1){
if(isMutiEp){
sprintf(newIdentifier,"%s_%d",propertiesbuf[0],ep);
}else{
sprintf(newIdentifier,"%s_%d",propertiesTmp,ep);
}
}else{
if(isMutiEp){
sprintf(newIdentifier,"%s",propertiesbuf[0]);
}else{
sprintf(newIdentifier,"%s",propertiesTmp);
}
}
INFO_PRINT("[%s][%d]valueStr:%s\n",__FUNCTION__,__LINE__,valueStr);
INFO_PRINT("[%s][%d]newIdentifier:%s\n",__FUNCTION__,__LINE__,newIdentifier);
if(strcmp(setDevnode->productCode,"3062") == 0){
kk_indoorair_property_db_get_value_directly((const char*)setDeviceCode,(const char*)newIdentifier,oldvalueStr,ep);
}else{
kk_property_db_get_value_directly((const char*)setDeviceCode,(const char*)newIdentifier,oldvalueStr);
}
INFO_PRINT("[%s][%d]oldvalueStr:%s\n",__FUNCTION__,__LINE__,oldvalueStr);
INFO_PRINT("[%s][%d]setDeviceCode:%s\n",__FUNCTION__,__LINE__,setDeviceCode);
if(strcmp(oldvalueStr,valueStr) == 0){
continue;
}else{
char *paramstr = NULL;
cJSON *params = cJSON_CreateObject();
if(property->data_value.type == KK_TSL_DATA_TYPE_INT ||
property->data_value.type == KK_TSL_DATA_TYPE_ENUM||
property->data_value.type == KK_TSL_DATA_TYPE_BOOL){
cJSON_AddNumberToObject(params, newIdentifier, propertyItem->valueint);
//if(strstr(newIdentifier,"PowerSwitch") != NULL && propertyItem->valueint == 0){
//offflag = 1;
//}
}else if(property->data_value.type == KK_TSL_DATA_TYPE_DOUBLE){
cJSON_AddNumberToObject(params, newIdentifier, propertyItem->valuedouble);
}else{
cJSON_AddStringToObject(params, newIdentifier, propertyItem->valuestring);
}
if(strcmp(setDevnode->productCode,"3062") == 0){
memset(epStr,0x0,sizeof(epStr));
sprintf(epStr,"%d",ep);
cJSON_DeleteItemFromObject(param, "epNum");
cJSON_AddStringToObject(param, "epNum", epStr);
paramstr=cJSON_Print(param);
offflag = 1;
}else{
paramstr=cJSON_Print(params);
}
kk_msg_execute_property_set(setDevnode->productCode,setDevnode->deviceCode,paramstr,setDevnode->fatherDeviceCode);
free(paramstr);
cJSON_Delete(params);
if(offflag){
break;
}
usleep(500000);
}
}
}
return 0;
}
static int _kk_manual_mutictrl_ctrl(char *sceneId,char *deviceCode,int ep,cJSON *param,int isMutiEp)
{
char *sqlCmd = NULL;
sqlite3_stmt *stmt;
char *pdeviceCode = NULL;
int res = 0;
int epNum = 0;
int isManualDev = 0;
int isAutoCtrlDev = 0;
dm_mgr_dev_node_t *node = NULL;
kk_scene_ctx_t *ctx = _kk_scene_get_ctx();
isManualDev = _kk_check_manualMutiCtrlDev((const char*)deviceCode);//上报的设备是否是需要手动触发多控设备
sqlCmd = sqlite3_mprintf("select * from SceneActionInfo WHERE sceneId= '%s' and type = '%s'",sceneId,"action/thing/group");//actice判断设备是否移入待分配
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
pdeviceCode = (char*)sqlite3_column_text(stmt,DB_SCENEACTION_DEVICECODE);
epNum = sqlite3_column_int(stmt, DB_SCENEACTION_EPNUM);
if(strcmp(pdeviceCode,deviceCode) == 0 && ep == epNum){//过滤掉刚上报的这路
continue;
}
isAutoCtrlDev = _kk_check_manualMutiCtrlDev((const char*)pdeviceCode);
if(isAutoCtrlDev == 0){//过滤下自动多控设备,手动多控设备先都手动执行下
continue;
}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
_kk_manual_mutictrl_set(param,pdeviceCode,epNum,deviceCode,isMutiEp);
}
sqlite3_free(sqlCmd);
sqlite3_finalize(stmt);
if(isManualDev){
sqlCmd = sqlite3_mprintf("select * from SceneActionInfo WHERE sceneId= '%s' and type = '%s'",sceneId,"action/thing/group");//actice判断设备是否移入待分配
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
pdeviceCode = (char*)sqlite3_column_text(stmt,DB_SCENEACTION_DEVICECODE);
epNum = sqlite3_column_int(stmt, DB_SCENEACTION_EPNUM);
if(strcmp(pdeviceCode,deviceCode) == 0 && ep == epNum){
continue;
}
isAutoCtrlDev = _kk_check_manualMutiCtrlDev((const char*)pdeviceCode);
if(isAutoCtrlDev == 0){//手动多控设备先都手动执行下,过滤下自动多控设备
_kk_manual_mutictrl_set(param,pdeviceCode,epNum,deviceCode,isMutiEp);
break;
}
}
sqlite3_free(sqlCmd);
sqlite3_finalize(stmt);
}
return SUCCESS_RETURN;
}
int kk_manual_mutictrl_execute(const char*deviceCode,cJSON *param)
{
int res = 0,idx = 0;
dm_mgr_dev_node_t *node = NULL;
kk_tsl_data_t *property = NULL;
cJSON *propertyItem = NULL;
int ep = 0;
char *propertiesbuf[64] = {0};
char propertiesTmp[64] = {0};
int num = 0;
int isMutiEp = 0;
char sceneId[16] = {0};
kk_scene_ctx_t *ctx = _kk_scene_get_ctx();
res = dm_mgr_get_device_by_devicecode((char*)deviceCode, &node);
for(idx = 0; idx < node->dev_shadow->property_number; idx++){//解析当前设备上报的epnum
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
propertyItem = cJSON_GetObjectItem(param, property->identifier);
if(propertyItem != NULL){
if(strstr(property->identifier,"_") != NULL){
memset(propertiesTmp,0x0,sizeof(propertiesTmp));
memcpy(propertiesTmp,property->identifier,strlen(property->identifier));
split(propertiesTmp,"_",propertiesbuf,&num);
if(num == 2){
ep = atoi(propertiesbuf[1]);
isMutiEp = 1;
}else{
ep = 1;
}
}else{
ep = 1;
}
break;
}
}
if(strcmp(node->productCode,"3062") == 0){ //空调网关
cJSON * epJson = cJSON_GetObjectItem(param, "epNum");
if(epJson == NULL){
INFO_PRINT("[%s][%d]\n",__FUNCTION__,__LINE__);
return -1;
}
ep = atoi(epJson->valuestring);
if(ep == 1){//空调网关第一路为网关本身,不处理
INFO_PRINT("[%s][%d]\n",__FUNCTION__,__LINE__);
return -1;
}
}
res = _kk_get_MutiCtrl_sceneId((char*)deviceCode,sceneId,ep);
if(res != 0){
INFO_PRINT("[%s][%d]\n",__FUNCTION__,__LINE__);
return -1;
}
INFO_PRINT("sceneId:%s\n",sceneId);
_kk_manual_mutictrl_ctrl(sceneId,(char*)deviceCode,ep,param,isMutiEp);
return SUCCESS_RETURN;
}
#endif
\ No newline at end of file
#ifndef __KK_MUTICTRL_HANDLE_H__
#define __KK_MUTICTRL_HANDLE_H__
#include "cJSON.h"
int kk_virtual_mutictrl_check(const char*deviceCode,cJSON *param);
int kk_manual_mutictrl_execute(const char*deviceCode,cJSON *param);
#endif
\ No newline at end of file
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include "kk_dm_mng.h" #include "kk_dm_mng.h"
#include <time.h> #include <time.h>
#include "kk_scene_pollution_check.h" #include "kk_scene_pollution_check.h"
#include "kk_mutictrl_handle.h"
/************************************************************* /*************************************************************
全局变量定义 全局变量定义
*************************************************************/ *************************************************************/
...@@ -1293,15 +1293,7 @@ int kk_scene_parse_scene_condition(const cJSON* str,const char *sceneId) ...@@ -1293,15 +1293,7 @@ int kk_scene_parse_scene_condition(const cJSON* str,const char *sceneId)
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
/************************************************************
*功能描述:解析执行动作
*输入参数:sceneId:对应场景Id;
str:执行动作的CJSON字串
isUpdate:1,updateScene;0,addScene
*输出参数:无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
static int _kk_scene_LightStripSpecialAction_handle(cJSON* propertyValue,char *deviceCode,int ep,int idelay,char *sceneId,char *fatherDeviceCode) static int _kk_scene_LightStripSpecialAction_handle(cJSON* propertyValue,char *deviceCode,int ep,int idelay,char *sceneId,char *fatherDeviceCode)
{ {
kk_scene_action_detail_t info = {0}; kk_scene_action_detail_t info = {0};
...@@ -1389,6 +1381,29 @@ static int _kk_scene_LightStripSpecialAction_handle(cJSON* propertyValue,char *d ...@@ -1389,6 +1381,29 @@ static int _kk_scene_LightStripSpecialAction_handle(cJSON* propertyValue,char *d
} }
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
static int _kk_scene_AirConditionerIndoorUnitSpecialAction_handle(cJSON* propertyValue,char *deviceCode,int ep,int idelay,char *sceneId,char *fatherDeviceCode)
{
kk_scene_action_detail_t info = {0};
cJSON * PowerSwitch = cJSON_GetObjectItem(propertyValue,"PowerSwitch");
if(PowerSwitch != NULL && PowerSwitch->type==cJSON_Number){
sprintf(info.propertyValue,"%d",PowerSwitch->valueint);
memcpy(info.propertyName,"PowerSwitch",strlen("PowerSwitch"));
memcpy(info.deviceCode,deviceCode,strlen(deviceCode));
info.epNum = ep;
info.delay = idelay;
kk_scene_action_add(fatherDeviceCode,sceneId,info);
}
return SUCCESS_RETURN;
}
/************************************************************
*功能描述:解析执行动作
*输入参数:sceneId:对应场景Id;
str:执行动作的CJSON字串
isUpdate:1,updateScene;0,addScene
*输出参数:无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdate) int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdate)
{ {
int res = 0; int res = 0;
...@@ -1532,9 +1547,12 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat ...@@ -1532,9 +1547,12 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat
if(propertyValue->type==cJSON_Number){ if(propertyValue->type==cJSON_Number){
snprintf(propertyValueStr,sizeof(propertyValueStr),"%d",propertyValue->valueint); snprintf(propertyValueStr,sizeof(propertyValueStr),"%d",propertyValue->valueint);
}else if(propertyValue->type==cJSON_Object){ }else if(propertyValue->type==cJSON_Object){
if(strcmp(propertyName->valuestring,"LightStripSpecialAction") == 0){ if(strcmp(propertyName->valuestring,"LightStripSpecialAction") == 0){//灯带场景自定义
_kk_scene_LightStripSpecialAction_handle(propertyValue,deviceCode->valuestring,iepnum,idelay,(char*)sceneId,node->fatherDeviceCode); _kk_scene_LightStripSpecialAction_handle(propertyValue,deviceCode->valuestring,iepnum,idelay,(char*)sceneId,node->fatherDeviceCode);
} }
else if(strcmp(propertyName->valuestring,"AirConditionerIndoorUnitSpecialAction") == 0){
_kk_scene_AirConditionerIndoorUnitSpecialAction_handle(propertyValue,deviceCode->valuestring,iepnum,idelay,(char*)sceneId,node->fatherDeviceCode);
}
char *str = cJSON_PrintUnformatted(propertyValue); char *str = cJSON_PrintUnformatted(propertyValue);
snprintf(propertyValueStr,sizeof(propertyValueStr),"%s",str); snprintf(propertyValueStr,sizeof(propertyValueStr),"%s",str);
free(str); free(str);
...@@ -1557,6 +1575,8 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat ...@@ -1557,6 +1575,8 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat
}else{ }else{
memcpy(info.propertyName,propertyName->valuestring,strlen(propertyName->valuestring)); memcpy(info.propertyName,propertyName->valuestring,strlen(propertyName->valuestring));
} }
}else if(strcmp(node->productCode,"3062") == 0){
memcpy(info.propertyName,propertyName->valuestring,strlen(propertyName->valuestring));
}else{ }else{
if(iepnum > 1 && strstr(propertyName->valuestring,"_") == NULL){ if(iepnum > 1 && strstr(propertyName->valuestring,"_") == NULL){
sprintf(info.propertyName,"%s_%d",propertyName->valuestring,iepnum); sprintf(info.propertyName,"%s_%d",propertyName->valuestring,iepnum);
...@@ -1568,7 +1588,8 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat ...@@ -1568,7 +1588,8 @@ int kk_scene_parse_scene_action(const cJSON* str,const char *sceneId,int isUpdat
info.epNum = iepnum; info.epNum = iepnum;
info.delay = idelay; info.delay = idelay;
if(strcmp(propertyName->valuestring,"LightStripSpecialAction") != 0){ if(strcmp(propertyName->valuestring,"LightStripSpecialAction") != 0 &&
strcmp(propertyName->valuestring,"AirConditionerIndoorUnitSpecialAction") != 0){
if(strcmp(node->productCode,"5004") == 0 && strcmp(propertyValueStr,"2") == 0){ if(strcmp(node->productCode,"5004") == 0 && strcmp(propertyValueStr,"2") == 0){
//虚拟灯取反由中控逻辑来处理,不需要下发给网关 //虚拟灯取反由中控逻辑来处理,不需要下发给网关
}else{ }else{
...@@ -2739,127 +2760,7 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param) ...@@ -2739,127 +2760,7 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
sqlite3_free(sqlCmd); sqlite3_free(sqlCmd);
return res; return res;
} }
static int _kk_virtual_mutictrl_ctrl(char *sceneId,int val,char *deviceCode,int ep)
{
char *sqlCmd = NULL;
sqlite3_stmt *stmt;
char *pdeviceCode = NULL;
int res = 0;
int epNum = 0;
dm_mgr_dev_node_t *node = NULL;
kk_scene_ctx_t *ctx = _kk_scene_get_ctx();
sqlCmd = sqlite3_mprintf("select * from SceneActionInfo WHERE sceneId= '%s' and type = '%s'",sceneId,"action/thing/group");//actice判断设备是否移入待分配
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
pdeviceCode = (char*)sqlite3_column_text(stmt,DB_SCENEACTION_DEVICECODE);
epNum = sqlite3_column_int(stmt, DB_SCENEACTION_EPNUM);
if(strcmp(pdeviceCode,deviceCode) == 0 && ep == epNum){
continue;
}
res = dm_mgr_get_device_by_devicecode((char*)pdeviceCode, &node);
//if (res != SUCCESS_RETURN || strcmp(node->productCode,"5004") != 0) {
//continue;
//}
cJSON *param = cJSON_CreateObject();
if(kk_is_mutiEp_device(pdeviceCode) == 1){
if(epNum == 1){
cJSON_AddNumberToObject(param, "PowerSwitch_1", val);
}else if(epNum == 2){
cJSON_AddNumberToObject(param, "PowerSwitch_2", val);
}else if(epNum == 3){
cJSON_AddNumberToObject(param, "PowerSwitch_3", val);
}else if(epNum == 4){
cJSON_AddNumberToObject(param, "PowerSwitch_4", val);
}else{
cJSON_Delete(param);
continue;
}
}else{
cJSON_AddNumberToObject(param, "PowerSwitch", val);
}
char *paramstr=cJSON_Print(param);
kk_msg_execute_property_set(node->productCode,node->deviceCode,paramstr,node->fatherDeviceCode);
free(paramstr);
cJSON_Delete(param);
}
return SUCCESS_RETURN;
}
void split(char *src,const char *separator,char **dest,int *num);
static int _kk_virtual_mutictrl_check(const char*deviceCode,cJSON *param)
{
char *sqlCmd = NULL;
sqlite3_stmt *stmt;
char *type = NULL;
char *sceneId = NULL;
int res = 0,idx = 0;
dm_mgr_dev_node_t *node = NULL;
kk_tsl_data_t *property = NULL;
cJSON *propertyItem = NULL;
int value = -1;
char scene_id_bak[64][16] = {0};
int i = 0,count = 0;
int repeat = 0;
int ep = 0,epNum = 0;
char *propertiesbuf[64] = {0};
char propertiesTmp[64] = {0};
int num = 0;
kk_scene_ctx_t *ctx = _kk_scene_get_ctx();
res = dm_mgr_get_device_by_devicecode((char*)deviceCode, &node);
for(idx = 0; idx < node->dev_shadow->property_number; idx++){
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
if(property == NULL || strstr(property->identifier,"PowerSwitch") == NULL){
continue;
}
propertyItem = cJSON_GetObjectItem(param, property->identifier);
if(propertyItem != NULL){
if(strstr(property->identifier,"_") != NULL){
memset(propertiesTmp,0x0,sizeof(propertiesTmp));
memcpy(propertiesTmp,property->identifier,strlen(property->identifier));
split(propertiesTmp,"_",propertiesbuf,&num);
if(num == 2){
ep = atoi(propertiesbuf[1]);
}else{
ep = 1;
}
}else{
ep = 1;
}
value = propertyItem->valueint;
break;
}
}
if(value == -1){
return FAIL_RETURN;
}
sqlCmd = sqlite3_mprintf("select * from SceneActionInfo WHERE deviceCode= '%s' and active = '%d'",deviceCode,1);//actice判断设备是否移入待分配
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
repeat = 0;
type = (char*)sqlite3_column_text(stmt,DB_SCENEACTION_TYPE);
epNum = sqlite3_column_int(stmt, DB_SCENEACTION_EPNUM);
if(strcmp(type,"action/thing/group") != 0 || epNum != ep){
continue;
}
sceneId = (char*)sqlite3_column_text(stmt,DB_SCENEACTION_SCENEID);
for(i = 0; i < count; i++){//检测同个设备在同个场景中设置不同的动作,只需rebuild一次
if(strcmp(scene_id_bak[i],sceneId) == 0){
repeat = 1;
break;
}
}
if(repeat){
continue;
}
_kk_virtual_mutictrl_ctrl(sceneId,value,(char*)deviceCode,ep);
if(count < 64){
memcpy(scene_id_bak[count],sceneId,strlen(sceneId));
count++;
}
}
return SUCCESS_RETURN;
}
/************************************************************ /************************************************************
*功能描述:IFTT场景检测 *功能描述:IFTT场景检测
*输入参数:param:属性CJSON内容 *输入参数:param:属性CJSON内容
...@@ -2872,7 +2773,7 @@ int kk_scene_iftt_check(const char*deviceCode,cJSON *param) ...@@ -2872,7 +2773,7 @@ int kk_scene_iftt_check(const char*deviceCode,cJSON *param)
{ {
INFO_PRINT("deviceCode:%s\n",deviceCode); INFO_PRINT("deviceCode:%s\n",deviceCode);
BodySensorTrigger_report(deviceCode,1,param); BodySensorTrigger_report(deviceCode,1,param);
_kk_virtual_mutictrl_check(deviceCode,param);//虚拟灯的多控检测 kk_manual_mutictrl_execute(deviceCode,param);//虚拟灯的多控检测
return kk_scene_query_trigger_info(deviceCode,param); return kk_scene_query_trigger_info(deviceCode,param);
} }
...@@ -3041,7 +2942,17 @@ static int _kk_rebuild_device_active(char *sceneid) ...@@ -3041,7 +2942,17 @@ static int _kk_rebuild_device_active(char *sceneid)
_kk_scene_LightStripSpecialAction_handle(propertyValueJson,pDeviceCode,epNum,idelay,(char*)sceneid,(char*)gwDeviceCode); _kk_scene_LightStripSpecialAction_handle(propertyValueJson,pDeviceCode,epNum,idelay,(char*)sceneid,(char*)gwDeviceCode);
cJSON_Delete(propertyValueJson); cJSON_Delete(propertyValueJson);
} }
}else if(strcmp(propertyName,"CustomAction") == 0){//空调内机的场景属性 }else if(strcmp(propertyName,"AirConditionerIndoorUnitSpecialAction") == 0){
if(strstr(propertyValueStr,"{")!=NULL &&strstr(propertyValueStr,"}")!=NULL){
cJSON* propertyValueJson = cJSON_Parse(propertyValueStr);
if (propertyValueJson == NULL) {
ERROR_PRINT("cJSON_Parse ERROR!!!");
return FAIL_RETURN;
}
_kk_scene_AirConditionerIndoorUnitSpecialAction_handle(propertyValueJson,pDeviceCode,epNum,idelay,(char*)sceneid,(char*)gwDeviceCode);
cJSON_Delete(propertyValueJson);
}
}else if(strcmp(propertyName,"CustomAction") == 0){//所有空调内机的场景属性
if(strstr(propertyValueStr,"{")!=NULL &&strstr(propertyValueStr,"}")!=NULL){ if(strstr(propertyValueStr,"{")!=NULL &&strstr(propertyValueStr,"}")!=NULL){
res = dm_mgr_get_device_by_devicecode(pDeviceCode,&node); res = dm_mgr_get_device_by_devicecode(pDeviceCode,&node);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
......
...@@ -96,15 +96,12 @@ int kk_pollution_condition_check(char *deviceCode,int grade) ...@@ -96,15 +96,12 @@ int kk_pollution_condition_check(char *deviceCode,int grade)
char currentValue[64] = {0}; char currentValue[64] = {0};
num = sizeof(g_pollutionMap)/sizeof(kk_pollution_t); num = sizeof(g_pollutionMap)/sizeof(kk_pollution_t);
for(i = 0; i < num; i++){ for(i = 0; i < num; i++){
printf("------------->g_pollutionMap[i].identifier:%s\n",g_pollutionMap[i].identifier);
memset(currentValue,0x0,sizeof(currentValue)); memset(currentValue,0x0,sizeof(currentValue));
kk_property_db_get_value_directly(deviceCode,g_pollutionMap[i].identifier,currentValue); kk_property_db_get_value_directly(deviceCode,g_pollutionMap[i].identifier,currentValue);
if(strcmp(currentValue,"") == 0){ if(strcmp(currentValue,"") == 0){
continue; continue;
} }
printf("------------->currentValue:%s\n",currentValue);
ret = kk_pollution_level_check(g_pollutionMap[i].levelMap,atoi(currentValue),4); ret = kk_pollution_level_check(g_pollutionMap[i].levelMap,atoi(currentValue),4);
printf("------------->ret:%d\n",ret);
if(ret != -1){ if(ret != -1){
if(grade == 1){ if(grade == 1){
if(ret == 1){ if(ret == 1){
...@@ -131,7 +128,6 @@ int kk_pm25_condition_check(char *deviceCode) ...@@ -131,7 +128,6 @@ int kk_pm25_condition_check(char *deviceCode)
int i = 0; int i = 0;
int ret = 0; int ret = 0;
char currentValue[64] = {0}; char currentValue[64] = {0};
kk_property_db_get_value_directly(deviceCode,"PM2.5",currentValue); kk_property_db_get_value_directly(deviceCode,"PM2.5",currentValue);
if(strcmp(currentValue,"") == 0){ if(strcmp(currentValue,"") == 0){
return 0; return 0;
......
...@@ -280,7 +280,7 @@ ...@@ -280,7 +280,7 @@
} }
} }
], ],
"identifier": "Alarm", "identifier": "sirenAlarm",
"method": "thing.event.sirenAlarm.post", "method": "thing.event.sirenAlarm.post",
"name": "sirenAlarm", "name": "sirenAlarm",
"type": "alarm", "type": "alarm",
......
{ {
"schema": "https://iot-ap.ikonke.com/model/product_3064.json", "schema": "https://iot-ap.ikonke.com/model/product_3064.json",
"productType": "Doorlock", "productType": "Doorlock",
"version": "1.2", "version": "1.3",
"profile": { "profile": {
"heartbeat": "1200", "heartbeat": "1200",
"productCode": "3064", "productCode": "3064",
"productName": "秦穹智能门锁枪黑Z3S(KONKE)", "productName": "秦穹智能门锁枪黑Z3S(KONKE)",
"sleepTime": "30000" "sleepTime": "30000"
}, },
"services": [ "services": [
{ {
"outputData": [], "outputData": [],
"identifier": "set", "identifier": "set",
"inputData": [ "inputData": [
{ {
"identifier": "remoteOpenDoorSwitch", "identifier": "remoteOpenDoorSwitch",
"name": "远程控制使能", "name": "远程控制使能",
"dataType": { "dataType": {
"type": "enum", "type": "enum",
"specs": { "specs": {
"0":"关闭", "0":"关闭",
"1":"开启" "1":"开启"
} }
} }
} }
], ],
"method": "thing.service.property.set", "method": "thing.service.property.set",
"name": "set", "name": "set",
"required": true, "required": true,
"callType": "async", "callType": "async",
"desc": "属性设置" "desc": "属性设置"
}, },
{ {
"outputData": [ "outputData": [
{ {
"identifier": "remoteOpenDoorSwitch", "identifier": "remoteOpenDoorSwitch",
"name": "远程控制使能", "name": "远程控制使能",
"dataType": { "dataType": {
"type": "enum", "type": "enum",
"specs": { "specs": {
"0":"关闭", "0":"关闭",
"1":"开启" "1":"开启"
} }
} }
}, },
{ {
"identifier": "Battery", "identifier": "Battery",
"name": "电池电量", "name": "电池电量",
"dataType": { "dataType": {
"type": "double", "type": "double",
"specs": { "specs": {
"min": "0", "min": "0",
"max": "100", "max": "100",
"unit": "%", "unit": "%",
"unitName": "百分比", "unitName": "百分比",
"step": "0.01" "step": "0.01"
} }
} }
} }
], ],
"identifier": "get", "identifier": "get",
"inputData": [ "inputData": [
"remoteOpenDoorSwitch", "remoteOpenDoorSwitch",
"Battery" "Battery"
], ],
"method": "thing.service.property.get", "method": "thing.service.property.get",
"name": "get", "name": "get",
"required": true, "required": true,
"callType": "async", "callType": "async",
"desc": "属性获取" "desc": "属性获取"
}, },
{ {
"outputData": [ "outputData": [
{ {
"identifier": "openfeedback", "identifier": "openfeedback",
"name": "远程开锁反馈", "name": "远程开锁反馈",
"dataType": { "dataType": {
"type": "enum", "type": "enum",
"specs": { "specs": {
"0":"成功", "0":"成功",
"1":"密码错误", "1":"密码错误",
"16":"不支持远程开锁", "16":"不支持远程开锁",
"18":"系统已锁定", "18":"系统已锁定",
"19":"远程开门未使能", "19":"远程开门未使能",
"255":"未知错误" "255":"未知错误"
} }
} }
} }
], ],
"identifier": "LockOpenNotification", "identifier": "LockOpenNotification",
"inputData": [ "inputData": [
{ {
"identifier": "password", "identifier": "password",
"name": "远程开锁密码", "name": "远程开锁密码",
"dataType": { "dataType": {
"type": "text", "type": "text",
"length": "64" "length": "64"
} }
} }
], ],
"method": "thing.service.LockOpenNotification", "method": "thing.service.LockOpenNotification",
"name": "LockOpenNotification", "name": "LockOpenNotification",
"required": true, "required": true,
"callType": "async", "callType": "async",
"desc": "远程开锁" "desc": "远程开锁"
} }
], ],
"properties": [ "properties": [
{ {
"identifier": "remoteOpenDoorSwitch", "identifier": "remoteOpenDoorSwitch",
"name": "远程控制使能", "name": "远程控制使能",
"accessMode": "rw", "accessMode": "rw",
"required": true, "required": true,
"dataType": { "dataType": {
"type": "enum", "type": "enum",
"specs": { "specs": {
"0":"关闭", "0":"关闭",
"1":"开启" "1":"开启"
} }
} }
}, },
{ {
"identifier": "Battery", "identifier": "Battery",
"name": "电池电量", "name": "电池电量",
"accessMode": "r", "accessMode": "r",
"required": false, "required": false,
"dataType": { "dataType": {
"type": "double", "type": "double",
"specs": { "specs": {
"min": "0", "min": "0",
"max": "100", "max": "100",
"unit": "%", "unit": "%",
"unitName": "百分比", "unitName": "百分比",
"step": "0.01" "step": "0.01"
} }
} }
} }
], ],
"events": [ "events": [
{ {
"outputData": [ "outputData": [
{ {
"identifier": "remoteOpenDoorSwitch", "identifier": "remoteOpenDoorSwitch",
"name": "远程控制使能", "name": "远程控制使能",
"dataType": { "dataType": {
"type": "enum", "type": "enum",
"specs": { "specs": {
"0":"关闭", "0":"关闭",
"1":"开启" "1":"开启"
} }
} }
}, },
{ {
"identifier": "Battery", "identifier": "Battery",
"name": "电池电量", "name": "电池电量",
"dataType": { "dataType": {
"type": "double", "type": "double",
"specs": { "specs": {
"min": "0", "min": "0",
"max": "100", "max": "100",
"unit": "%", "unit": "%",
"unitName": "百分比", "unitName": "百分比",
"step": "0.01" "step": "0.01"
} }
} }
} }
], ],
"identifier": "property", "identifier": "property",
"method": "thing.event.property.post", "method": "thing.event.property.post",
"name": "property", "name": "property",
"type": "info", "type": "info",
"required": true, "required": true,
"desc": "属性上报" "desc": "属性上报"
}, },
{ {
"outputData": [ "outputData": [
{ {
"identifier": "KeyID", "identifier": "KeyID",
"name": "用户ID", "name": "用户ID",
"dataType": { "dataType": {
"type": "text", "type": "text",
"length" : "10" "length" : "10"
} }
}, },
{ {
"identifier": "KeyRole", "identifier": "KeyRole",
"name": "用户类型", "name": "用户类型",
"dataType": { "dataType": {
"type": "enum", "type": "enum",
"specs": { "specs": {
"1":"管理员", "1":"管理员",
"2":"普通用户", "2":"普通用户",
"3":"临时用户" "3":"临时用户"
} }
} }
}, },
{ {
"identifier": "KeyType", "identifier": "KeyType",
"name": "开锁方式", "name": "开锁方式",
"dataType": { "dataType": {
"type": "enum", "type": "enum",
"specs": { "specs": {
"1":"指纹", "1":"指纹",
"2":"密码", "2":"密码",
"3":"刷卡", "3":"刷卡",
"4":"APP远程开锁", "4":"APP远程开锁",
"5":"机械钥匙", "5":"机械钥匙",
"6":"蓝牙", "6":"蓝牙",
"7":"劫持报警", "7":"劫持报警",
"8":"限时临时密码" "8":"限时临时密码"
} }
} }
} }
], ],
"identifier": "LockOpenNotification", "identifier": "LockOpenNotification",
"method": "thing.event.LockOpenNotification.post", "method": "thing.event.LockOpenNotification.post",
"name": "LockOpenNotification", "name": "LockOpenNotification",
"type": "info", "type": "info",
"required": true, "required": true,
"desc": "开门上报" "desc": "开门上报"
}, },
{ {
"outputData": [ "outputData": [
{ {
"identifier": "KeyID", "identifier": "KeyID",
"name": "用户ID", "name": "用户ID",
"dataType": { "dataType": {
"type": "text", "type": "text",
"length" : "10" "length" : "10"
} }
}, },
{ {
"identifier": "KeyRole", "identifier": "KeyRole",
"name": "用户类型", "name": "用户类型",
"dataType": { "dataType": {
"type": "enum", "type": "enum",
"specs": { "specs": {
"1":"管理员", "1":"管理员",
"2":"普通用户", "2":"普通用户",
"3":"临时用户" "3":"临时用户"
} }
} }
}, },
{ {
"identifier": "KeyType", "identifier": "KeyType",
"name": "开锁方式", "name": "开锁方式",
"dataType": { "dataType": {
"type": "enum", "type": "enum",
"specs": { "specs": {
"1":"指纹", "1":"指纹",
"2":"密码", "2":"密码",
"3":"刷卡", "3":"刷卡",
"4":"APP远程开锁", "4":"APP远程开锁",
"5":"机械钥匙", "5":"机械钥匙",
"6":"蓝牙", "6":"蓝牙",
"7":"劫持报警", "7":"劫持报警",
"8":"限时临时密码" "8":"限时临时密码"
} }
} }
} }
], ],
"identifier": "KeyAddNotification", "identifier": "KeyAddNotification",
"method": "thing.event.KeyAddNotification.post", "method": "thing.event.KeyAddNotification.post",
"name": "KeyAddNotification", "name": "KeyAddNotification",
"type": "info", "type": "info",
"required": true, "required": true,
"desc": "添加用户上报" "desc": "添加用户上报"
}, },
{ {
"outputData": [ "outputData": [
{ {
"identifier": "KeyID", "identifier": "KeyID",
"name": "用户ID", "name": "用户ID",
"dataType": { "dataType": {
"type": "text", "type": "text",
"length" : "10" "length" : "10"
} }
}, },
{ {
"identifier": "KeyRole", "identifier": "KeyRole",
"name": "用户类型", "name": "用户类型",
"dataType": { "dataType": {
"type": "enum", "type": "enum",
"specs": { "specs": {
"1":"管理员", "1":"管理员",
"2":"普通用户", "2":"普通用户",
"3":"临时用户" "3":"临时用户"
} }
} }
}, },
{ {
"identifier": "KeyType", "identifier": "KeyType",
"name": "开锁方式", "name": "开锁方式",
"dataType": { "dataType": {
"type": "enum", "type": "enum",
"specs": { "specs": {
"1":"指纹", "1":"指纹",
"2":"密码", "2":"密码",
"3":"刷卡", "3":"刷卡",
"4":"APP远程开锁", "4":"APP远程开锁",
"5":"机械钥匙", "5":"机械钥匙",
"6":"蓝牙", "6":"蓝牙",
"7":"劫持报警", "7":"劫持报警",
"8":"限时临时密码" "8":"限时临时密码"
} }
} }
} }
], ],
"identifier": "KeyDeletedNotification", "identifier": "KeyDeletedNotification",
"method": "thing.event.KeyDeletedNotification.post", "method": "thing.event.KeyDeletedNotification.post",
"name": "KeyDeletedNotification", "name": "KeyDeletedNotification",
"type": "info", "type": "info",
"required": true, "required": true,
"desc": "删除用户上报" "desc": "删除用户上报"
}, },
{ {
"identifier": "DoorBell", "identifier": "DoorBell",
"method": "thing.event.DoorBell.post", "method": "thing.event.DoorBell.post",
"name": "DoorBell", "name": "DoorBell",
"type": "alarm", "type": "alarm",
"required": true, "required": true,
"desc": "门铃事件" "desc": "门铃事件"
}, },
{ {
"outputData": [ "outputData": [
{ {
"identifier": "DismantleState", "identifier": "DismantleState",
"name": "拆卸状态", "name": "拆卸状态",
"dataType": { "dataType": {
"type": "enum", "type": "enum",
"specs": { "specs": {
"0": "正常", "0": "正常",
"1": "被拆卸" "1": "被拆卸"
} }
} }
} }
], ],
"identifier": "TamperAlarm", "identifier": "TamperAlarm",
"method": "thing.event.TamperAlarm.post", "method": "thing.event.TamperAlarm.post",
"name": "TamperAlarm", "name": "TamperAlarm",
"type": "alert", "type": "alert",
"required": true, "required": true,
"desc": "防拆告警" "desc": "防拆告警"
}, },
{ {
"outputData": [ "outputData": [
{ {
"identifier": "Battery", "identifier": "Battery",
"name": "电池电量", "name": "电池电量",
"dataType": { "dataType": {
"type": "double", "type": "double",
"specs": { "specs": {
"min": "0.0", "min": "0.0",
"max": "100.0", "max": "100.0",
"unit": "%", "unit": "%",
"unitName": "百分比", "unitName": "百分比",
"step": "0.01" "step": "0.01"
} }
} }
} }
], ],
"identifier": "BatteryAlarm", "identifier": "BatteryAlarm",
"method": "thing.event.BatteryAlarm.post", "method": "thing.event.BatteryAlarm.post",
"name": "BatteryAlarm", "name": "BatteryAlarm",
"type": "alert", "type": "alert",
"required": true, "required": true,
"desc": "低电量告警" "desc": "低电量告警"
} },
] {
"identifier": "MultipleOpenLockFailedAlarm",
"method": "thing.event.MultipleOpenLockFailedAlarm.post",
"name": "MultipleOpenLockFailedAlarm",
"type": "alarm",
"required": true,
"desc": "暴力破解告警"
}
]
} }
\ No newline at end of file
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