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

【修改内容】增加主机离线再上线的子设备属性上报处理

【提交人】陈伟灿
parent 18348bd2
...@@ -16,7 +16,7 @@ typedef struct { ...@@ -16,7 +16,7 @@ typedef struct {
typedef struct { typedef struct {
int isOnline; int isOnline;
int starttime; time_t starttime;
char deviceCode[DEVICE_CODE_MAXLEN]; char deviceCode[DEVICE_CODE_MAXLEN];
struct list_head linked_list; struct list_head linked_list;
} kk_gw_status_ctx_t; } kk_gw_status_ctx_t;
...@@ -46,7 +46,7 @@ uint64_t s_start_time = 0; ...@@ -46,7 +46,7 @@ uint64_t s_start_time = 0;
void *kk_heartbeat_yield(void *args) void *kk_heartbeat_yield(void *args)
{ {
kk_heartbeat_ctx_t *ctx = _kk_heartbeat_get_ctx(); kk_heartbeat_ctx_t *ctx = _kk_heartbeat_get_ctx();
uint64_t current_time = 0; time_t current_time = 0;
int res = 0; int res = 0;
dm_mgr_dev_node_t *node = NULL; dm_mgr_dev_node_t *node = NULL;
kk_gw_status_ctx_t *gw = NULL; kk_gw_status_ctx_t *gw = NULL;
...@@ -57,7 +57,7 @@ void *kk_heartbeat_yield(void *args) ...@@ -57,7 +57,7 @@ void *kk_heartbeat_yield(void *args)
if (!list_empty(&ctx->gw_status_list)) { if (!list_empty(&ctx->gw_status_list)) {
list_for_each_entry(gw, &ctx->gw_status_list, linked_list, kk_gw_status_ctx_t){ list_for_each_entry(gw, &ctx->gw_status_list, linked_list, kk_gw_status_ctx_t){
if(gw->isOnline){ if(gw->isOnline == KK_DEV_ONLINE){
list_del(&gw->linked_list); list_del(&gw->linked_list);
//kk_subDev_send_property_get(gw->deviceCode); //kk_subDev_send_property_get(gw->deviceCode);
...@@ -75,7 +75,7 @@ void *kk_heartbeat_yield(void *args) ...@@ -75,7 +75,7 @@ void *kk_heartbeat_yield(void *args)
if((current_time - gw->starttime) >= node->hb_timeout){ if((current_time - gw->starttime) >= node->hb_timeout){
//printf("&&&&&&&&&&&&&&&&&&&&&&[%s][%d]\n",__FUNCTION__,__LINE__); //printf("&&&&&&&&&&&&&&&&&&&&&&[%s][%d]\n",__FUNCTION__,__LINE__);
INFO_PRINT("GW is off line now!!! deviceCode:%s\n",node->deviceCode); INFO_PRINT("GW is off line now!!! deviceCode:%s\n",node->deviceCode);
dm_mgr_set_dev_onoffline(node,1); dm_mgr_set_dev_onoffline(node,KK_DEV_OFFLINE);
list_del(&gw->linked_list); list_del(&gw->linked_list);
free(gw); free(gw);
} }
...@@ -88,10 +88,8 @@ void *kk_heartbeat_yield(void *args) ...@@ -88,10 +88,8 @@ void *kk_heartbeat_yield(void *args)
} }
} }
_kk_heartbeat_unlock(); _kk_heartbeat_unlock();
dm_mgr_check_heartbeat_timeout(current_time); dm_mgr_check_heartbeat_timeout(current_time);
sleep(1); sleep(1);
} }
return NULL; return NULL;
} }
...@@ -140,7 +138,7 @@ int kk_dm_gw_status_check_push(const char *deviceCode) ...@@ -140,7 +138,7 @@ int kk_dm_gw_status_check_push(const char *deviceCode)
memset(gw, 0, sizeof(kk_gw_status_ctx_t)); memset(gw, 0, sizeof(kk_gw_status_ctx_t));
_kk_heartbeat_lock(); _kk_heartbeat_lock();
memcpy(gw->deviceCode,deviceCode,strlen(deviceCode)); memcpy(gw->deviceCode,deviceCode,strlen(deviceCode));
gw->isOnline = 0; gw->isOnline = KK_DEV_UNKNOW;
gw->starttime = HAL_GetTime(); gw->starttime = HAL_GetTime();
INIT_LIST_HEAD(&gw->linked_list); INIT_LIST_HEAD(&gw->linked_list);
list_add_tail(&gw->linked_list, &ctx->gw_status_list); list_add_tail(&gw->linked_list, &ctx->gw_status_list);
...@@ -158,7 +156,7 @@ int kk_dm_gw_status_update_online(const char *deviceCode) ...@@ -158,7 +156,7 @@ int kk_dm_gw_status_update_online(const char *deviceCode)
if(0 == strcmp(gw->deviceCode,deviceCode)) if(0 == strcmp(gw->deviceCode,deviceCode))
{ {
INFO_PRINT("kk_dm_gw_status_update_online find!!!\n"); INFO_PRINT("kk_dm_gw_status_update_online find!!!\n");
gw->isOnline = 1; gw->isOnline = KK_DEV_ONLINE;
_kk_heartbeat_unlock(); _kk_heartbeat_unlock();
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
......
...@@ -375,7 +375,7 @@ int dm_mgr_get_device_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _O ...@@ -375,7 +375,7 @@ int dm_mgr_get_device_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _O
} }
int dm_mgr_update_timestamp_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN],uint64_t timestamp) int dm_mgr_update_timestamp_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN],time_t timestamp)
{ {
dm_mgr_ctx *ctx = _dm_mgr_get_ctx(); dm_mgr_ctx *ctx = _dm_mgr_get_ctx();
dm_mgr_dev_node_t *search_node = NULL; dm_mgr_dev_node_t *search_node = NULL;
...@@ -402,40 +402,52 @@ int dm_mgr_set_dev_onoffline(dm_mgr_dev_node_t *node,int isOffline) ...@@ -402,40 +402,52 @@ int dm_mgr_set_dev_onoffline(dm_mgr_dev_node_t *node,int isOffline)
} }
if(isOffline){ if(isOffline){
INFO_PRINT("---------->dev timeout,send offline\n"); INFO_PRINT("---------->dev timeout,send offline\n");
node->isOffline = 1; node->isOffline = KK_DEV_OFFLINE;
iotx_dm_dev_offline(node->devid); iotx_dm_dev_offline(node->devid);
kk_subDev_update_offline(node->isOffline,node->deviceCode); kk_subDev_update_offline(node->isOffline,node->deviceCode);
} }
else{ else{
INFO_PRINT("---------->dev online,send online\n"); INFO_PRINT("---------->dev online,send online\n");
node->isOffline = 0; node->isOffline = KK_DEV_ONLINE;
iotx_dm_dev_online(node->devid); iotx_dm_dev_online(node->devid);
kk_subDev_update_offline(node->isOffline,node->deviceCode); if(node->dev_type == KK_DM_DEVICE_CCU){
/*如果网关在线,下发对应子设备的属性获取*/ /*先上报主机属性*/
if(node->dev_type == KK_DM_DEVICE_GATEWAY){ dm_msg_ccu_property_post(node);
kk_subDev_send_property_get(node->deviceCode); /*再报对应网关和子设备的属性,主机上线后子设备属性直接从数据库获取并上报*/
kk_subDev_send_property_get_from_db();
}
else{
kk_subDev_update_offline(node->isOffline,node->deviceCode);
/*如果网关在线,下发对应子设备的属性获取*/
if(node->dev_type == KK_DM_DEVICE_GATEWAY){
kk_subDev_send_property_get(node->deviceCode);
}
} }
} }
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
int dm_mgr_check_heartbeat_timeout(uint64_t timestamp) int dm_mgr_check_heartbeat_timeout(time_t timestamp)
{ {
dm_mgr_ctx *ctx = _dm_mgr_get_ctx(); dm_mgr_ctx *ctx = _dm_mgr_get_ctx();
dm_mgr_dev_node_t *search_node = NULL; dm_mgr_dev_node_t *search_node = NULL;
_dm_mgr_mutex_lock(); _dm_mgr_mutex_lock();
list_for_each_entry(search_node, &ctx->dev_list, linked_list, dm_mgr_dev_node_t) { list_for_each_entry(search_node, &ctx->dev_list, linked_list, dm_mgr_dev_node_t) {
if(search_node->dev_type == KK_DM_DEVICE_CCU){
continue;
}
if(search_node->hb_timeout == 0){ if(search_node->hb_timeout == 0){
search_node->hb_timeout = DEFAULT_HEARTBEAT_TIMEOUT; search_node->hb_timeout = DEFAULT_HEARTBEAT_TIMEOUT;
} }
if(((int)timestamp - (int)search_node->timestamp) >= search_node->hb_timeout/*search_node->hb_timeout*/){ if((timestamp - search_node->timestamp) >= search_node->hb_timeout/*search_node->hb_timeout*/){
if(search_node->isOffline == 0){ if(search_node->isOffline != KK_DEV_OFFLINE){
dm_mgr_set_dev_onoffline(search_node,1); dm_mgr_set_dev_onoffline(search_node,1);
} }
} }
else{
if(search_node->isOffline == KK_DEV_OFFLINE){
/*如果是离线状态,上报在线给云端*/
dm_mgr_set_dev_onoffline(search_node,0);
}
}
} }
_dm_mgr_mutex_unlock(); _dm_mgr_mutex_unlock();
return SUCCESS_RETURN; return SUCCESS_RETURN;
...@@ -500,7 +512,7 @@ int dm_mgr_init(void) ...@@ -500,7 +512,7 @@ int dm_mgr_init(void)
HAL_Get_mac(mac); HAL_Get_mac(mac);
res = dm_mgr_device_create(KK_DM_DEVICE_CCU,KK_DM_CCU_DEVICE_PRODUCT_CODE,"CCU_66666",mac,"",0,&devId,&heartbeat); res = dm_mgr_device_create(KK_DM_DEVICE_CCU,KK_DM_CCU_DEVICE_PRODUCT_CODE,"CCU_66666",mac,"",KK_DEV_UNKNOW,&devId,&heartbeat);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
goto ERROR; goto ERROR;
} }
......
...@@ -29,7 +29,7 @@ typedef struct { ...@@ -29,7 +29,7 @@ typedef struct {
char productType[PRODUCT_TYPE_MAXLEN]; char productType[PRODUCT_TYPE_MAXLEN];
char isOffline; char isOffline;
int hb_timeout; //heartbeat time int hb_timeout; //heartbeat time
uint64_t timestamp; time_t timestamp;
struct list_head linked_list; struct list_head linked_list;
} dm_mgr_dev_node_t; } dm_mgr_dev_node_t;
......
...@@ -883,6 +883,20 @@ int dm_msg_thing_property_post_all(char *deviceCode) ...@@ -883,6 +883,20 @@ int dm_msg_thing_property_post_all(char *deviceCode)
} }
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
int dm_msg_ccu_property_post(dm_mgr_dev_node_t *node)
{
if(node == NULL){
return INVALID_PARAMETER;
}
char *payload_property = kk_tsl_get_post_property_str(node->dev_shadow,NULL);
if(payload_property != NULL){
dm_mgr_upstream_thing_property_post(node->devid, payload_property, strlen(payload_property),0);
free(payload_property);
payload_property = NULL;
}
return SUCCESS_RETURN;
}
int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params) int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params)
{ {
...@@ -894,7 +908,7 @@ int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params) ...@@ -894,7 +908,7 @@ int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params)
cJSON *propertyItem = NULL; cJSON *propertyItem = NULL;
char tmpValue[20] = {0}; char tmpValue[20] = {0};
if(params == NULL || deviceCode == NULL){ if(params == NULL || deviceCode == NULL){
return FAIL_RETURN; return INVALID_PARAMETER;
} }
res = dm_mgr_get_device_by_devicecode(deviceCode, &node); res = dm_mgr_get_device_by_devicecode(deviceCode, &node);
......
...@@ -773,14 +773,10 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) ...@@ -773,14 +773,10 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
} }
kk_property_db_update("CCU_66666"); kk_property_db_update("CCU_66666");
if(s_CloudStatus){ if(s_CloudStatus){
node->isOffline = KK_DEV_ONLINE;
iotx_dm_dev_online(KK_DM_DEVICE_CCU_DEVICEID);//first online,report the online status iotx_dm_dev_online(KK_DM_DEVICE_CCU_DEVICEID);//first online,report the online status
usleep(200000); usleep(200000);
char *payload_property = kk_tsl_get_post_property_str(node->dev_shadow,NULL); dm_msg_ccu_property_post(node);
if(payload_property != NULL){
dm_mgr_upstream_thing_property_post(node->devid, payload_property, strlen(payload_property),0);
free(payload_property);
payload_property = NULL;
}
} }
}else if (strstr(typeJson->valuestring,KK_THING_OTA_DEVICE_UPGRADE)){ }else if (strstr(typeJson->valuestring,KK_THING_OTA_DEVICE_UPGRADE)){
INFO_PRINT("ota upgrade... \n"); INFO_PRINT("ota upgrade... \n");
...@@ -2252,12 +2248,11 @@ int kk_mid_subdev_add(int devType, char productCode[PRODUCT_CODE_MAXLEN], char d ...@@ -2252,12 +2248,11 @@ int kk_mid_subdev_add(int devType, char productCode[PRODUCT_CODE_MAXLEN], char d
int devid = 0; int devid = 0;
int heartbeat = 0; int heartbeat = 0;
dm_mgr_dev_node_t *node = NULL; dm_mgr_dev_node_t *node = NULL;
res = dm_mgr_subdev_create(devType,productCode,deviceCode,mac,fatherDeviceCode,0,&devid,&heartbeat); res = dm_mgr_subdev_create(devType,productCode,deviceCode,mac,fatherDeviceCode,KK_DEV_ONLINE,&devid,&heartbeat);
if (res != SUCCESS_RETURN && TSL_ALREADY_EXIST != res) { if (res != SUCCESS_RETURN && TSL_ALREADY_EXIST != res) {
ERROR_PRINT("subdev create Failed\n"); ERROR_PRINT("subdev create Failed\n");
return FAIL_RETURN; return FAIL_RETURN;
} }
INFO_PRINT("subdev open susseed, devid = %d\n", devid);
if (TSL_ALREADY_EXIST == res){ if (TSL_ALREADY_EXIST == res){
//todo //todo
...@@ -2293,12 +2288,11 @@ int kk_mid_subdev_batch_add( char productCode[PRODUCT_CODE_MAXLEN], char deviceC ...@@ -2293,12 +2288,11 @@ int kk_mid_subdev_batch_add( char productCode[PRODUCT_CODE_MAXLEN], char deviceC
int res = 0; int res = 0;
int devid = 0; int devid = 0;
int heartbeat = 0; int heartbeat = 0;
res = dm_mgr_subdev_create(KK_DM_DEVICE_SUBDEV,productCode,deviceCode,mac,fatherDeviceCode,0,&devid,&heartbeat); res = dm_mgr_subdev_create(KK_DM_DEVICE_SUBDEV,productCode,deviceCode,mac,fatherDeviceCode,KK_DEV_ONLINE,&devid,&heartbeat);
if (res != SUCCESS_RETURN && TSL_ALREADY_EXIST != res) { if (res != SUCCESS_RETURN && TSL_ALREADY_EXIST != res) {
ERROR_PRINT("subdev create Failed\n"); ERROR_PRINT("subdev create Failed\n");
return FAIL_RETURN; return FAIL_RETURN;
} }
INFO_PRINT("subdev open susseed, devid = %d\n", devid);
if (TSL_ALREADY_EXIST == res){ if (TSL_ALREADY_EXIST == res){
//todo //todo
......
...@@ -314,13 +314,13 @@ int kk_property_db_update(const char *deviceCode) ...@@ -314,13 +314,13 @@ int kk_property_db_update(const char *deviceCode)
kk_property_db_update_value(deviceCode,property->identifier,tmpValue); kk_property_db_update_value(deviceCode,property->identifier,tmpValue);
} }
else if(property->data_value.type == KK_TSL_DATA_TYPE_FLOAT){ else if(property->data_value.type == KK_TSL_DATA_TYPE_FLOAT){
sprintf(tmpValue,"%d",property->data_value.value_float); sprintf(tmpValue,"%f",property->data_value.value_float);
kk_property_db_update_value(deviceCode,property->identifier,tmpValue); kk_property_db_update_value(deviceCode,property->identifier,tmpValue);
} }
else if(property->data_value.type == KK_TSL_DATA_TYPE_DOUBLE){ else if(property->data_value.type == KK_TSL_DATA_TYPE_DOUBLE){
sprintf(tmpValue,"%d",property->data_value.value_double); sprintf(tmpValue,"%f",property->data_value.value_double);
kk_property_db_update_value(deviceCode,property->identifier,tmpValue); kk_property_db_update_value(deviceCode,property->identifier,tmpValue);
} }
else if(property->data_value.type == KK_TSL_DATA_TYPE_TEXT|| else if(property->data_value.type == KK_TSL_DATA_TYPE_TEXT||
......
...@@ -109,7 +109,7 @@ static int _kk_load_subDevice(void) ...@@ -109,7 +109,7 @@ static int _kk_load_subDevice(void)
sqlite3_column_text(stmt, DB_DEVICECODE), sqlite3_column_text(stmt, DB_DEVICECODE),
sqlite3_column_text(stmt, DB_MAC), sqlite3_column_text(stmt, DB_MAC),
sqlite3_column_text(stmt, DB_FATHERDEVICECODE), sqlite3_column_text(stmt, DB_FATHERDEVICECODE),
1,&devId,&heartbeat); KK_DEV_UNKNOW,&devId,&heartbeat);
if(res != SUCCESS_RETURN){ if(res != SUCCESS_RETURN){
ERROR_PRINT("[%s][%d]dm_mgr_subdev_create FAIL!!!\n",__FUNCTION__,__LINE__); ERROR_PRINT("[%s][%d]dm_mgr_subdev_create FAIL!!!\n",__FUNCTION__,__LINE__);
...@@ -307,6 +307,35 @@ int kk_subDev_update_auth(int isAuth,const char *deviceCode) ...@@ -307,6 +307,35 @@ int kk_subDev_update_auth(int isAuth,const char *deviceCode)
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
int kk_subDev_send_property_get_from_db(void)
{
const char *searchCmd = "select * from SubDeviceInfo;";
sqlite3_stmt *stmt;
int isOffline = 0;
kk_subDb_ctx_t *ctx = _kk_subDb_get_ctx();
int res = 0;
dm_mgr_dev_node_t *node = NULL;
_kk_subDb_lock();
sqlite3_prepare_v2(ctx->pDb, searchCmd, strlen(searchCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
isOffline = sqlite3_column_int(stmt, DB_DEVTYPE);
if(isOffline == KK_DEV_ONLINE){
res = dm_mgr_get_device_by_devicecode(sqlite3_column_text(stmt, DB_DEVICECODE), &node);
if (res != SUCCESS_RETURN) {
continue;
}
iotx_dm_dev_online(node->devid);
dm_msg_thing_property_post_all(sqlite3_column_text(stmt, DB_DEVICECODE));
}
}
sqlite3_finalize(stmt);
_kk_subDb_unlock();
return SUCCESS_RETURN;
}
int kk_subDev_send_property_get(const char *fatherDeviceCode) int kk_subDev_send_property_get(const char *fatherDeviceCode)
{ {
int res = 0; int res = 0;
...@@ -334,9 +363,8 @@ int kk_subDev_send_property_get(const char *fatherDeviceCode) ...@@ -334,9 +363,8 @@ int kk_subDev_send_property_get(const char *fatherDeviceCode)
//if(!strcmp(pDeviceCode,"842E14FFFE9A26CA")){ //if(!strcmp(pDeviceCode,"842E14FFFE9A26CA")){
//continue; //continue;
//} //}
/*发送之前先置为offline*/ /*发送之前先置为KK_DEV_UNKNOW*/
node->isOffline = 1; node->isOffline = KK_DEV_UNKNOW;
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_msg_execute_property_get(node); kk_msg_execute_property_get(node);
usleep(100000); usleep(100000);
} }
......
...@@ -284,7 +284,6 @@ void gw2mid_cb(void* data, int len, char* chalMark){ ...@@ -284,7 +284,6 @@ void gw2mid_cb(void* data, int len, char* chalMark){
} }
} }
extern uint64_t s_start_time;
void kk_platMsg_handle(void* data, char* chalMark){ void kk_platMsg_handle(void* data, char* chalMark){
char *out; char *out;
...@@ -744,7 +743,7 @@ void *ccu_property_monitor(void *args) ...@@ -744,7 +743,7 @@ void *ccu_property_monitor(void *args)
int needReport = 0; int needReport = 0;
int time_second = 60; int time_second = 60;
dm_mgr_dev_node_t *node = NULL; dm_mgr_dev_node_t *node = NULL;
dm_mgr_search_dev_by_devid(KK_DM_DEVICE_CCU_DEVICEID,&node);
while (mid_ctx->g_ccuProChg_dispatch_thread_running) { while (mid_ctx->g_ccuProChg_dispatch_thread_running) {
if(kk_get_cloud_recv_status() == 0){ if(kk_get_cloud_recv_status() == 0){
...@@ -752,7 +751,9 @@ void *ccu_property_monitor(void *args) ...@@ -752,7 +751,9 @@ void *ccu_property_monitor(void *args)
sleep(10); sleep(10);
continue; continue;
} }
dm_mgr_search_dev_by_devid(KK_DM_DEVICE_CCU_DEVICEID,&node);
//dm_mgr_update_timestamp_by_devicecode(node->deviceCode,HAL_GetTime());
node->timestamp = HAL_GetTime();
HAL_Get_IP(s_IP,NULL); HAL_Get_IP(s_IP,NULL);
res = kk_tsl_get_value(kk_tsl_get_property_value,node->dev_shadow,KK_TSL_CCU_WANIP_IDENTIFIER,s_IP_TSL,NULL); res = kk_tsl_get_value(kk_tsl_get_property_value,node->dev_shadow,KK_TSL_CCU_WANIP_IDENTIFIER,s_IP_TSL,NULL);
if(res != SUCCESS_RETURN){ if(res != SUCCESS_RETURN){
...@@ -762,7 +763,7 @@ void *ccu_property_monitor(void *args) ...@@ -762,7 +763,7 @@ void *ccu_property_monitor(void *args)
if(strcmp(s_IP,s_IP_TSL)){ if(strcmp(s_IP,s_IP_TSL)){
kk_tsl_set_value(kk_tsl_set_property_value,node->dev_shadow,KK_TSL_CCU_WANIP_IDENTIFIER,NULL,s_IP); kk_tsl_set_value(kk_tsl_set_property_value,node->dev_shadow,KK_TSL_CCU_WANIP_IDENTIFIER,NULL,s_IP);
INFO_PRINT("current ip:%s,before ip:%s\n",s_IP,s_IP_TSL); INFO_PRINT("current ip:%s,before ip:%s\n",s_IP,s_IP_TSL);
kk_property_db_update("CCU_66666"); kk_property_db_update(node->deviceCode);
needReport = 1; needReport = 1;
} }
} }
......
...@@ -237,7 +237,7 @@ extern uint64_t s_start_time; ...@@ -237,7 +237,7 @@ extern uint64_t s_start_time;
void *kk_scene_yield(void *args) void *kk_scene_yield(void *args)
{ {
uint64_t current_time = 0; time_t current_time = 0;
kk_scene_action_delay_t *actionDelayInfo = NULL; kk_scene_action_delay_t *actionDelayInfo = NULL;
kk_scene_action_delay_t *pTemp = NULL; kk_scene_action_delay_t *pTemp = NULL;
kk_scene_timer_list_t *scene_timer_list = NULL; kk_scene_timer_list_t *scene_timer_list = NULL;
...@@ -849,6 +849,7 @@ int kk_scene_get_scene_info(const char* sceneId,int *sceneType,int *enable) ...@@ -849,6 +849,7 @@ int kk_scene_get_scene_info(const char* sceneId,int *sceneType,int *enable)
static char kk_scene_date_to_week(time_t t) static char kk_scene_date_to_week(time_t t)
{ {
struct tm *p = localtime(&t); struct tm *p = localtime(&t);
INFO_PRINT("kk_scene_date_to_week t p->tm_wday:%d\n",p->tm_wday);
return ((p->tm_wday == 0)?7 : p->tm_wday); return ((p->tm_wday == 0)?7 : p->tm_wday);
} }
static int kk_scene_update_starttime(kk_scene_timer_list_t *pInfo,int starttime,int current) static int kk_scene_update_starttime(kk_scene_timer_list_t *pInfo,int starttime,int current)
...@@ -885,14 +886,23 @@ static int kk_scene_update_starttime(kk_scene_timer_list_t *pInfo,int starttime, ...@@ -885,14 +886,23 @@ static int kk_scene_update_starttime(kk_scene_timer_list_t *pInfo,int starttime,
} }
static int kk_scene_creat_new_starttime(time_t starttime,time_t current) static time_t kk_scene_creat_new_starttime(time_t starttime,time_t current)
{ {
struct tm *s = localtime(&starttime); int hour,min,sec;
time_t newTime = 0;
struct tm *s = localtime(&starttime);
hour = s->tm_hour;
min = s->tm_min;
sec = s->tm_sec;
struct tm *c = localtime(&current); struct tm *c = localtime(&current);
c->tm_hour = s->tm_hour; c->tm_hour = hour;
c->tm_min = s->tm_min; c->tm_min = min;
c->tm_sec = s->tm_sec; c->tm_sec = sec;
return mktime(c); newTime = mktime(c);
INFO_PRINT("kk_scene_creat_new_starttime:%ld\n",newTime);
return newTime;
} }
int kk_scene_check_condition(const char *sceneId) int kk_scene_check_condition(const char *sceneId)
...@@ -901,12 +911,12 @@ int kk_scene_check_condition(const char *sceneId) ...@@ -901,12 +911,12 @@ int kk_scene_check_condition(const char *sceneId)
char *sqlCmd = NULL; char *sqlCmd = NULL;
char curWeek = 0; char curWeek = 0;
char repeatday = 0; char repeatday = 0;
int startTime = 0,startTime_m = 0; time_t startTime = 0,startTime_m = 0;
int endTime = 0,endTime_m = 0; time_t endTime = 0,endTime_m = 0;
int duration = 0; int duration = 0;
sqlite3_stmt *stmt; sqlite3_stmt *stmt;
kk_scene_ctx_t *ctx = _kk_scene_get_ctx(); kk_scene_ctx_t *ctx = _kk_scene_get_ctx();
uint64_t current = HAL_GetTime(); time_t current = HAL_GetTime();
curWeek = kk_scene_date_to_week(current); curWeek = kk_scene_date_to_week(current);
sqlCmd = sqlite3_mprintf("select * from SceneConditionInfo WHERE sceneId = '%s'",sceneId); sqlCmd = sqlite3_mprintf("select * from SceneConditionInfo WHERE sceneId = '%s'",sceneId);
...@@ -922,11 +932,19 @@ int kk_scene_check_condition(const char *sceneId) ...@@ -922,11 +932,19 @@ int kk_scene_check_condition(const char *sceneId)
if(current >= startTime_m && current <= (startTime_m + duration)){ if(current >= startTime_m && current <= (startTime_m + duration)){
res = SUCCESS_RETURN; res = SUCCESS_RETURN;
} }
else{
INFO_PRINT("time not match current:%ld,startTime_m:%ld,repeatday:%d\n",current,startTime_m,repeatday);
}
} }
else{ else{
if(current >= startTime && current <= (startTime + duration)){ if(current >= startTime && current <= (startTime + duration)){
res = SUCCESS_RETURN; res = SUCCESS_RETURN;
} }
else
{
INFO_PRINT("time not match current:%ld,startTime:%ld\n",current,startTime);
}
} }
} }
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
...@@ -1166,6 +1184,7 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param) ...@@ -1166,6 +1184,7 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
sqlCmd = sqlite3_mprintf("select * from SceneTriggerInfo WHERE deviceCode= '%s'",deviceCode); sqlCmd = sqlite3_mprintf("select * from SceneTriggerInfo WHERE deviceCode= '%s'",deviceCode);
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL); sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){ while(sqlite3_step(stmt) == SQLITE_ROW){
sceneId = sqlite3_column_text(stmt, DB_SCENETRIGGER_SCENEID); sceneId = sqlite3_column_text(stmt, DB_SCENETRIGGER_SCENEID);
identifier = sqlite3_column_text(stmt,DB_SCENETRIGGER_PROPERTYNAME); identifier = sqlite3_column_text(stmt,DB_SCENETRIGGER_PROPERTYNAME);
compareType = sqlite3_column_text(stmt,DB_SCENETRIGGER_COMPARETYPE); compareType = sqlite3_column_text(stmt,DB_SCENETRIGGER_COMPARETYPE);
...@@ -1195,6 +1214,7 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param) ...@@ -1195,6 +1214,7 @@ int kk_scene_query_trigger_info(const char *deviceCode,cJSON *param)
} }
int kk_scene_iftt_check(const char*deviceCode,cJSON *param) int kk_scene_iftt_check(const char*deviceCode,cJSON *param)
{ {
printf("[%s][%d] deviceCode:%s\n",__FUNCTION__,__LINE__,deviceCode);
return kk_scene_query_trigger_info(deviceCode,param); return kk_scene_query_trigger_info(deviceCode,param);
} }
......
...@@ -14,14 +14,14 @@ typedef struct { ...@@ -14,14 +14,14 @@ typedef struct {
} kk_scene_action_info_t; } kk_scene_action_info_t;
typedef struct kk_action_list{ typedef struct kk_action_list{
int starttime; time_t starttime;
kk_scene_action_info_t *action; kk_scene_action_info_t *action;
struct kk_action_list *next; struct kk_action_list *next;
} kk_scene_action_delay_t; } kk_scene_action_delay_t;
typedef struct kk_scene_timer_list{ typedef struct kk_scene_timer_list{
int starttime; time_t starttime;
int endtime; time_t endtime;
char sceneId[32]; char sceneId[32];
int repeatday; int repeatday;
struct kk_scene_timer_list *next; struct kk_scene_timer_list *next;
......
...@@ -83,6 +83,11 @@ ...@@ -83,6 +83,11 @@
#define DEFAULT_HEARTBEAT_TIMEOUT (60*4)// four minutes #define DEFAULT_HEARTBEAT_TIMEOUT (60*4)// four minutes
typedef enum {
KK_DEV_ONLINE = 0,
KK_DEV_OFFLINE,
KK_DEV_UNKNOW,
} kk_dev_status_e;
typedef enum { typedef enum {
KK_TSL_DATA_TARGET_SERVICE_INPUT_DATA, KK_TSL_DATA_TARGET_SERVICE_INPUT_DATA,
......
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