Commit 32ba1614 authored by 陈伟灿's avatar 陈伟灿

Merge branch 'cwc' into 'master'

【修改内容】增加场景定时功能

See merge request chenweican/k-sdk!65
parents b62eaff4 2a1afaf2
...@@ -101,6 +101,8 @@ typedef enum { ...@@ -101,6 +101,8 @@ typedef enum {
#define MSG_SCENE_TRIGGERS "triggers" #define MSG_SCENE_TRIGGERS "triggers"
#define MSG_SCENE_ITEMS "items" #define MSG_SCENE_ITEMS "items"
#define MSG_SCENE_TYPE "type" #define MSG_SCENE_TYPE "type"
#define MSG_SCENE_WEEK "week"
#define MSG_SCENE_TIME "time"
#define MSG_SCENE_EPNUM "epNum" #define MSG_SCENE_EPNUM "epNum"
#define MSG_SCENE_PROPERTYNAME "propertyName" #define MSG_SCENE_PROPERTYNAME "propertyName"
#define MSG_SCENE_COMPARETYPE "compareType" #define MSG_SCENE_COMPARETYPE "compareType"
...@@ -120,6 +122,8 @@ typedef enum { ...@@ -120,6 +122,8 @@ typedef enum {
#define MSG_SCENE_UPDATENOTIFICATION "updateSceneNotification" #define MSG_SCENE_UPDATENOTIFICATION "updateSceneNotification"
#define MSG_SCENE_DELETENOTIFICATION_SCENEID "deleteSceneNotification.sceneId" #define MSG_SCENE_DELETENOTIFICATION_SCENEID "deleteSceneNotification.sceneId"
#define MSG_SCENE_DELETENOTIFICATION "deleteSceneNotification" #define MSG_SCENE_DELETENOTIFICATION "deleteSceneNotification"
#define MSG_SCENE_EXECUTENOTIFICATION_SCENEID "executeSceneNotification.sceneId"
#define MSG_SCENE_EXECUTENOTIFICATION "executeSceneNotification"
......
...@@ -164,6 +164,29 @@ char *HAL_GetTimeStr(_IN_ char *buf, _IN_ int len) ...@@ -164,6 +164,29 @@ char *HAL_GetTimeStr(_IN_ char *buf, _IN_ int len)
} }
int HAL_Get_TimeZone(void)
{
int timezone = 0;
time_t t1, t2 ;
struct tm *tm_local, *tm_utc;
time(&t1);
t2 = t1;
tm_local = localtime(&t1);
t1 = mktime(tm_local) ;
tm_utc = gmtime(&t2);
t2 = mktime(tm_utc);
timezone = (t1 - t2) / 3600;
printf("%d\n", timezone);
return timezone;
}
void HAL_SleepMs(_IN_ uint32_t ms) void HAL_SleepMs(_IN_ uint32_t ms)
{ {
usleep(1000 * ms); usleep(1000 * ms);
......
...@@ -1228,7 +1228,6 @@ int kk_msg_execute_scene_set(const char* params,const char *fatherDeviceCode,int ...@@ -1228,7 +1228,6 @@ int kk_msg_execute_scene_set(const char* params,const char *fatherDeviceCode,int
cJSON_AddItemToObject(root, "info", infoObj); cJSON_AddItemToObject(root, "info", infoObj);
cJSON_AddItemToObject(root, "payload",payloadObj); cJSON_AddItemToObject(root, "payload",payloadObj);
void *buf = cJSON_Print(root); void *buf = cJSON_Print(root);
printf("----------------->buf:%s\n",buf);
kk_sendData2gw(buf, strlen(buf), fatherDeviceCode); kk_sendData2gw(buf, strlen(buf), fatherDeviceCode);
free(buf); free(buf);
free(req_info); free(req_info);
...@@ -1279,7 +1278,6 @@ int kk_msg_execute_scene_action(const char* params,const char *fatherDeviceCode) ...@@ -1279,7 +1278,6 @@ int kk_msg_execute_scene_action(const char* params,const char *fatherDeviceCode)
cJSON_AddItemToObject(root, "info", infoObj); cJSON_AddItemToObject(root, "info", infoObj);
cJSON_AddItemToObject(root, "payload",payloadObj); cJSON_AddItemToObject(root, "payload",payloadObj);
void *buf = cJSON_Print(root); void *buf = cJSON_Print(root);
printf("----------------->buf:%s\n",buf);
kk_sendData2gw(buf, strlen(buf), fatherDeviceCode); kk_sendData2gw(buf, strlen(buf), fatherDeviceCode);
free(buf); free(buf);
free(req_info); free(req_info);
......
This diff is collapsed.
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include "kk_property_db.h" #include "kk_property_db.h"
#include "sqlite3.h" #include "sqlite3.h"
int g_timezone = 8;
char * g_filerToPlatTable[] = char * g_filerToPlatTable[] =
{ {
{KK_REGISTER_TOPIC_REPLY}, {KK_REGISTER_TOPIC_REPLY},
...@@ -61,13 +61,15 @@ void kk_sendData2gw(void* data, int len, char* chalMark){ ...@@ -61,13 +61,15 @@ void kk_sendData2gw(void* data, int len, char* chalMark){
ERROR_PRINT(" chalMark is null"); ERROR_PRINT(" chalMark is null");
return; return;
} }
INFO_PRINT("start to send data to gw!!!\n");
INFO_PRINT("data:%s!!!\n",data);
if (kk_is_tcp_channel(chalMark) > -1){ if (kk_is_tcp_channel(chalMark) > -1){
kk_tcp_channel_ser_send(data, len, chalMark); kk_tcp_channel_ser_send(data, len, chalMark);
}else{ }else{
kk_ipc_send_ex(IPC_MID2PLAT, data, len + 1, chalMark); kk_ipc_send_ex(IPC_MID2PLAT, data, len + 1, chalMark);
} }
} }
static int kk_property_set_data_check(cJSON * payload,const char *deviceCode){ static int kk_property_set_data_check(cJSON * payload,const char *deviceCode){
cJSON *params = NULL; cJSON *params = NULL;
...@@ -110,14 +112,14 @@ static int kk_property_set_data_check(cJSON * payload,const char *deviceCode){ ...@@ -110,14 +112,14 @@ static int kk_property_set_data_check(cJSON * payload,const char *deviceCode){
if(current_data->data_value.type == KK_TSL_DATA_TYPE_INT){ if(current_data->data_value.type == KK_TSL_DATA_TYPE_INT){
value = propertyItem_1->valueint; value = propertyItem_1->valueint;
if(value < current_data->data_value.mix ||value > current_data->data_value.max ){ if(value < current_data->data_value.mix ||value > current_data->data_value.max ){
ERROR_PRINT("ERROR ------------>value:%d,mix:%d,max:%d\n",value,current_data->data_value.mix,current_data->data_value.max); ERROR_PRINT("ERROR !!!value:%d,mix:%d,max:%d\n",value,current_data->data_value.mix,current_data->data_value.max);
return INVALID_PARAMETER; return INVALID_PARAMETER;
} }
} }
else if(current_data->data_value.type == KK_TSL_DATA_TYPE_TEXT){ else if(current_data->data_value.type == KK_TSL_DATA_TYPE_TEXT){
if(strlen(propertyItem_1->valuestring) > current_data->data_value.length ){ if(strlen(propertyItem_1->valuestring) > current_data->data_value.length ){
ERROR_PRINT("ERROR ------------>strlen(propertyItem_1->valuestring):%d,current_data->data_value.length:%d\n",strlen(propertyItem_1->valuestring),current_data->data_value.length); ERROR_PRINT("ERROR !!!strlen(propertyItem_1->valuestring):%d,current_data->data_value.length:%d\n",strlen(propertyItem_1->valuestring),current_data->data_value.length);
return INVALID_PARAMETER; return INVALID_PARAMETER;
} }
} }
...@@ -138,14 +140,14 @@ static int kk_property_set_data_check(cJSON * payload,const char *deviceCode){ ...@@ -138,14 +140,14 @@ static int kk_property_set_data_check(cJSON * payload,const char *deviceCode){
if(current_data_1->data_value.type == KK_TSL_DATA_TYPE_INT){ if(current_data_1->data_value.type == KK_TSL_DATA_TYPE_INT){
value = propertyItem_2->valueint; value = propertyItem_2->valueint;
if(value < current_data_1->data_value.mix ||value > current_data_1->data_value.max ){ if(value < current_data_1->data_value.mix ||value > current_data_1->data_value.max ){
ERROR_PRINT("ERROR------------>value:%d,mix:%d,max:%d\n",value,current_data_1->data_value.mix,current_data_1->data_value.max); ERROR_PRINT("ERROR !!!value:%d,mix:%d,max:%d\n",value,current_data_1->data_value.mix,current_data_1->data_value.max);
return INVALID_PARAMETER; return INVALID_PARAMETER;
} }
} }
else if(current_data_1->data_value.type == KK_TSL_DATA_TYPE_TEXT){ else if(current_data_1->data_value.type == KK_TSL_DATA_TYPE_TEXT){
if(strlen(propertyItem_2->valuestring) > current_data_1->data_value.length ){ if(strlen(propertyItem_2->valuestring) > current_data_1->data_value.length ){
ERROR_PRINT("ERROR ------------>strlen(propertyItem_2->valuestring):%d,propertyItem_2->data_value.length:%d\n",strlen(propertyItem_2->valuestring),current_data_1->data_value.length); ERROR_PRINT("ERROR !!!strlen(propertyItem_2->valuestring):%d,propertyItem_2->data_value.length:%d\n",strlen(propertyItem_2->valuestring),current_data_1->data_value.length);
return INVALID_PARAMETER; return INVALID_PARAMETER;
} }
} }
...@@ -158,14 +160,14 @@ static int kk_property_set_data_check(cJSON * payload,const char *deviceCode){ ...@@ -158,14 +160,14 @@ static int kk_property_set_data_check(cJSON * payload,const char *deviceCode){
else if(property->data_value.type == KK_TSL_DATA_TYPE_INT){ else if(property->data_value.type == KK_TSL_DATA_TYPE_INT){
value = propertyItem->valueint; value = propertyItem->valueint;
if(value < property->data_value.mix ||value > property->data_value.max ){ if(value < property->data_value.mix ||value > property->data_value.max ){
ERROR_PRINT("ERROR ------------>value:%d,mix:%d,max:%d\n",value,property->data_value.mix,property->data_value.max); ERROR_PRINT("ERROR !!!value:%d,mix:%d,max:%d\n",value,property->data_value.mix,property->data_value.max);
return INVALID_PARAMETER; return INVALID_PARAMETER;
} }
} }
else if(property->data_value.type == KK_TSL_DATA_TYPE_TEXT){ else if(property->data_value.type == KK_TSL_DATA_TYPE_TEXT){
if(strlen(propertyItem->valuestring) > property->data_value.length ){ if(strlen(propertyItem->valuestring) > property->data_value.length ){
ERROR_PRINT("ERROR ------------>strlen(propertyItem->valuestring):%d,property->data_value.length:%d\n",strlen(propertyItem->valuestring),property->data_value.length ); ERROR_PRINT("ERROR !!!strlen(propertyItem->valuestring):%d,property->data_value.length:%d\n",strlen(propertyItem->valuestring),property->data_value.length );
return INVALID_PARAMETER; return INVALID_PARAMETER;
} }
} }
...@@ -178,7 +180,7 @@ static int kk_property_set_data_check(cJSON * payload,const char *deviceCode){ ...@@ -178,7 +180,7 @@ static int kk_property_set_data_check(cJSON * payload,const char *deviceCode){
} }
void mid_cb(void* data, int len){ void mid_cb(void* data, int len){
if (data != NULL){ if (data != NULL){
cJSON* payload;
cJSON *json; cJSON *json;
cJSON *info_root,*type; cJSON *info_root,*type;
cJSON*deviceCode; cJSON*deviceCode;
...@@ -203,15 +205,19 @@ void mid_cb(void* data, int len){ ...@@ -203,15 +205,19 @@ void mid_cb(void* data, int len){
cJSON_Delete(json); cJSON_Delete(json);
return; return;
} }
payload = cJSON_GetObjectItem(json, MSG_PAYLOAD_STR);
if (payload == NULL){
ERROR_PRINT(" params [%s] can't find \n",MSG_PAYLOAD_STR);
cJSON_Delete(json);
return;
}
/*****属性设置需要先检测设置参数是否超出物模型给定范围*******/ /*****属性设置需要先检测设置参数是否超出物模型给定范围*******/
if (strcmp(type->valuestring, KK_THING_SERVICE_PROPERTY_SET)==0){ if (strcmp(type->valuestring, KK_THING_SERVICE_PROPERTY_SET)==0){
cJSON* payload = cJSON_GetObjectItem(json, MSG_PAYLOAD_STR); res = kk_property_set_data_check(payload,deviceCode->valuestring);
if(payload != NULL){ if(res != SUCCESS_RETURN){
res = kk_property_set_data_check(payload,deviceCode->valuestring); cJSON_Delete(json);
if(res != SUCCESS_RETURN){ return;
return; }
}
}
} }
int devType = 0; int devType = 0;
...@@ -225,6 +231,10 @@ void mid_cb(void* data, int len){ ...@@ -225,6 +231,10 @@ void mid_cb(void* data, int len){
free(buf); free(buf);
} }
}else if(devType == KK_DM_DEVICE_GATEWAY){ }else if(devType == KK_DM_DEVICE_GATEWAY){
/*手机端主动删除设备,需要删除数据库相关内容,再下发给网关*/
if (strcmp(type->valuestring, KK_THING_TOPO_CHANGE_MSG)==0){
kk_topo_delete_handle(payload);
}
kk_sendData2gw(data, strlen(data), deviceCode->valuestring);//send to gw itself kk_sendData2gw(data, strlen(data), deviceCode->valuestring);//send to gw itself
}else if(devType == KK_DM_DEVICE_SUBDEV){ }else if(devType == KK_DM_DEVICE_SUBDEV){
dm_mgr_dev_node_t *gw_node = NULL; dm_mgr_dev_node_t *gw_node = NULL;
...@@ -843,6 +853,8 @@ int main(const int argc, const char **argv) ...@@ -843,6 +853,8 @@ int main(const int argc, const char **argv)
kk_area_init(); kk_area_init();
kk_scene_init(); kk_scene_init();
g_timezone = HAL_Get_TimeZone();
mid_ctx->g_mid_dispatch_thread_running = 1; mid_ctx->g_mid_dispatch_thread_running = 1;
res = pthread_create(&mid_ctx->g_mid_dispatch_thread, NULL, mid_dispatch_yield, NULL); res = pthread_create(&mid_ctx->g_mid_dispatch_thread, NULL, mid_dispatch_yield, NULL);
if (res < 0) { if (res < 0) {
......
This diff is collapsed.
...@@ -40,7 +40,6 @@ typedef struct kk_action_list{ ...@@ -40,7 +40,6 @@ typedef struct kk_action_list{
typedef struct kk_scene_timer_list{ typedef struct kk_scene_timer_list{
time_t starttime; time_t starttime;
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;
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
#include "kk_dm_mng.h" #include "kk_dm_mng.h"
#include "kk_log.h" #include "kk_log.h"
#define TSL_SUBDEVICE_PATH_FILE "/usr/kk/tsl/product_%s.json" #define TSL_SUBDEVICE_PATH_FILE "/usr/kk/tsl/product_%s.json"
#define TSL_GATEWAY_PATH_FILE "/usr/kk/tsl/gateway-%s.json" #define TSL_GATEWAY_PATH_FILE "/usr/kk/tsl/gateway_%s.json"
#define TSL_CCU_PATH_FILE "/usr/kk/tsl/ccu-%s.json" #define TSL_CCU_PATH_FILE "/usr/kk/tsl/ccu_%s.json"
#define TSL_SCENE_PATH_FILE "/usr/kk/tsl/ccu_%s_scene.json" #define TSL_SCENE_PATH_FILE "/usr/kk/tsl/ccu_%s_scene.json"
char* kk_load_json(const char *productCode,int type) char* kk_load_json(const char *productCode,int type)
......
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