Commit 2a1afaf2 authored by chen.weican's avatar chen.weican

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

【提交人】陈伟灿
parent b62eaff4
......@@ -101,6 +101,8 @@ typedef enum {
#define MSG_SCENE_TRIGGERS "triggers"
#define MSG_SCENE_ITEMS "items"
#define MSG_SCENE_TYPE "type"
#define MSG_SCENE_WEEK "week"
#define MSG_SCENE_TIME "time"
#define MSG_SCENE_EPNUM "epNum"
#define MSG_SCENE_PROPERTYNAME "propertyName"
#define MSG_SCENE_COMPARETYPE "compareType"
......@@ -120,6 +122,8 @@ typedef enum {
#define MSG_SCENE_UPDATENOTIFICATION "updateSceneNotification"
#define MSG_SCENE_DELETENOTIFICATION_SCENEID "deleteSceneNotification.sceneId"
#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)
}
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)
{
usleep(1000 * ms);
......
......@@ -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, "payload",payloadObj);
void *buf = cJSON_Print(root);
printf("----------------->buf:%s\n",buf);
kk_sendData2gw(buf, strlen(buf), fatherDeviceCode);
free(buf);
free(req_info);
......@@ -1279,7 +1278,6 @@ int kk_msg_execute_scene_action(const char* params,const char *fatherDeviceCode)
cJSON_AddItemToObject(root, "info", infoObj);
cJSON_AddItemToObject(root, "payload",payloadObj);
void *buf = cJSON_Print(root);
printf("----------------->buf:%s\n",buf);
kk_sendData2gw(buf, strlen(buf), fatherDeviceCode);
free(buf);
free(req_info);
......
This diff is collapsed.
......@@ -22,7 +22,7 @@
#include "kk_property_db.h"
#include "sqlite3.h"
int g_timezone = 8;
char * g_filerToPlatTable[] =
{
{KK_REGISTER_TOPIC_REPLY},
......@@ -61,6 +61,8 @@ void kk_sendData2gw(void* data, int len, char* chalMark){
ERROR_PRINT(" chalMark is null");
return;
}
INFO_PRINT("start to send data to gw!!!\n");
INFO_PRINT("data:%s!!!\n",data);
if (kk_is_tcp_channel(chalMark) > -1){
kk_tcp_channel_ser_send(data, len, chalMark);
......@@ -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){
value = propertyItem_1->valueint;
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;
}
}
else if(current_data->data_value.type == KK_TSL_DATA_TYPE_TEXT){
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;
}
}
......@@ -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){
value = propertyItem_2->valueint;
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;
}
}
else if(current_data_1->data_value.type == KK_TSL_DATA_TYPE_TEXT){
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;
}
}
......@@ -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){
value = propertyItem->valueint;
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;
}
}
else if(property->data_value.type == KK_TSL_DATA_TYPE_TEXT){
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;
}
}
......@@ -178,7 +180,7 @@ static int kk_property_set_data_check(cJSON * payload,const char *deviceCode){
}
void mid_cb(void* data, int len){
if (data != NULL){
cJSON* payload;
cJSON *json;
cJSON *info_root,*type;
cJSON*deviceCode;
......@@ -202,17 +204,21 @@ void mid_cb(void* data, int len){
ERROR_PRINT(" params [%s] or [%s] can't find \n",MSG_DEVICE_CODE_STR, MSG_TYPE_STR);
cJSON_Delete(json);
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){
cJSON* payload = cJSON_GetObjectItem(json, MSG_PAYLOAD_STR);
if(payload != NULL){
res = kk_property_set_data_check(payload,deviceCode->valuestring);
if(res != SUCCESS_RETURN){
cJSON_Delete(json);
return;
}
}
}
int devType = 0;
dm_mgr_get_devicetype_by_devicecode(deviceCode->valuestring,&devType);
......@@ -225,6 +231,10 @@ void mid_cb(void* data, int len){
free(buf);
}
}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
}else if(devType == KK_DM_DEVICE_SUBDEV){
dm_mgr_dev_node_t *gw_node = NULL;
......@@ -843,6 +853,8 @@ int main(const int argc, const char **argv)
kk_area_init();
kk_scene_init();
g_timezone = HAL_Get_TimeZone();
mid_ctx->g_mid_dispatch_thread_running = 1;
res = pthread_create(&mid_ctx->g_mid_dispatch_thread, NULL, mid_dispatch_yield, NULL);
if (res < 0) {
......
This diff is collapsed.
......@@ -40,7 +40,6 @@ typedef struct kk_action_list{
typedef struct kk_scene_timer_list{
time_t starttime;
time_t endtime;
char sceneId[32];
int repeatday;
struct kk_scene_timer_list *next;
......
......@@ -5,8 +5,8 @@
#include "kk_dm_mng.h"
#include "kk_log.h"
#define TSL_SUBDEVICE_PATH_FILE "/usr/kk/tsl/product_%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_GATEWAY_PATH_FILE "/usr/kk/tsl/gateway_%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"
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