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);
......
......@@ -235,7 +235,7 @@ int kk_get_cloud_recv_status(void){
return s_CloudStatusRecv;
}
static int kk_topo_delete_handle(cJSON *payload)
int kk_topo_delete_handle(cJSON *payload)
{
if(payload == NULL){
return FAIL_RETURN;
......@@ -696,6 +696,26 @@ static int kk_service_deleteScene_handle(const char *deviceCode,cJSON *param,cJS
}
return res;
}
static int kk_service_executeScene_handle(const char *deviceCode,cJSON *param,cJSON *msgId)
{
int res = 0;
kk_tsl_t *pSceneShadow = NULL;
if(deviceCode == NULL || param == NULL || msgId == NULL){
return INVALID_PARAMETER;
}
cJSON *sceneId = cJSON_GetObjectItem(param,MSG_SCENE_SCENEID);
if(sceneId == NULL) return FAIL_RETURN;
res = kk_scene_execute_scene(sceneId->valuestring);
if(res == SUCCESS_RETURN){
pSceneShadow = kk_scene_shadow();
if(pSceneShadow != NULL){
kk_tsl_set_value(kk_tsl_set_event_output_value,pSceneShadow,MSG_SCENE_EXECUTENOTIFICATION_SCENEID,NULL,sceneId->valuestring);
dm_msg_scene_event_post(deviceCode,MSG_SCENE_EXECUTENOTIFICATION,pSceneShadow,msgId->valuestring);
}
}
return res;
}
static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
{
......@@ -734,8 +754,6 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
_iotx_linkkit_upstream_mutex_unlock();
}else if (strstr(typeJson->valuestring,KK_ADD_TOPIC_REPLY)){
//====todo======
//
INFO_PRINT(" topic:add_reply \n");
dm_msg_response_payload_t response;
res = dm_msg_response_parse((char *)payload_Str, strlen(payload->valuestring)+1, &response);
......@@ -796,10 +814,6 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
INFO_PRINT("ota upgrade... \n");
kk_dm_ota_send(data, strlen(data)+1);
}else if(strcmp(typeJson->valuestring,KK_THING_TOPO_CHANGE_MSG) == 0){
INFO_PRINT(" topo change \n");
kk_topo_delete_handle(payload);
}else if(strcmp(typeJson->valuestring,KK_THING_SERVICE_REBOOT) == 0){
INFO_PRINT(" reboot called!!!\n");
dm_msg_thing_event_post(deviceCode->valuestring,MSG_REBOOT_REBOOTNOTIFICATION);
......@@ -893,6 +907,12 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
cJSON *msgId = cJSON_GetObjectItem(payload, MSG_SCENE_MSGID);
kk_service_deleteScene_handle(deviceCode->valuestring,paramStr,msgId);
}
else if(strcmp(typeJson->valuestring,KK_THING_SERVICE_EXECUTESCENE) == 0){
INFO_PRINT("execute scene \n");
cJSON *paramStr = cJSON_GetObjectItem(payload, MSG_PARAMS_STR);
cJSON *msgId = cJSON_GetObjectItem(payload, MSG_SCENE_MSGID);
kk_service_executeScene_handle(deviceCode->valuestring,paramStr,msgId);
}
else{
INFO_PRINT("Error msgtype!!! \n");
......@@ -901,657 +921,6 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
directReturn:
free(payload_Str);
cJSON_Delete(json);
#if 0
int res = 0;
void *callback;
#ifdef LOG_REPORT_TO_CLOUD
lite_cjson_t msg_id;
#endif
lite_cjson_t lite, lite_item_id, lite_item_devid, lite_item_serviceid, lite_item_payload, lite_item_ctx;
lite_cjson_t lite_item_code, lite_item_eventid, lite_item_utc, lite_item_rrpcid, lite_item_topo;
lite_cjson_t lite_item_pk, lite_item_time;
lite_cjson_t lite_item_version, lite_item_configid, lite_item_configsize, lite_item_gettype, lite_item_sign,
lite_item_signmethod, lite_item_url;
dm_log_info("Receive Message Type: %d", type);
if (payload) {
dm_log_info("Receive Message: %s", payload);
res = dm_utils_json_parse(payload, strlen(payload), cJSON_Invalid, &lite);
if (res != SUCCESS_RETURN) {
return;
}
#ifdef LOG_REPORT_TO_CLOUD
dm_utils_json_object_item(&lite, "msgid", 5, cJSON_Invalid, &msg_id);
#endif
dm_utils_json_object_item(&lite, IOTX_LINKKIT_KEY_ID, strlen(IOTX_LINKKIT_KEY_ID), cJSON_Invalid, &lite_item_id);
dm_utils_json_object_item(&lite, IOTX_LINKKIT_KEY_DEVID, strlen(IOTX_LINKKIT_KEY_DEVID), cJSON_Invalid,
&lite_item_devid);
dm_utils_json_object_item(&lite, IOTX_LINKKIT_KEY_SERVICEID, strlen(IOTX_LINKKIT_KEY_SERVICEID), cJSON_Invalid,
&lite_item_serviceid);
dm_utils_json_object_item(&lite, IOTX_LINKKIT_KEY_PAYLOAD, strlen(IOTX_LINKKIT_KEY_PAYLOAD), cJSON_Invalid,
&lite_item_payload);
dm_utils_json_object_item(&lite, IOTX_LINKKIT_KEY_CTX, strlen(IOTX_LINKKIT_KEY_CTX), cJSON_Invalid, &lite_item_ctx);
dm_utils_json_object_item(&lite, IOTX_LINKKIT_KEY_CODE, strlen(IOTX_LINKKIT_KEY_CODE), cJSON_Invalid, &lite_item_code);
dm_utils_json_object_item(&lite, IOTX_LINKKIT_KEY_EVENTID, strlen(IOTX_LINKKIT_KEY_EVENTID), cJSON_Invalid,
&lite_item_eventid);
dm_utils_json_object_item(&lite, IOTX_LINKKIT_KEY_UTC, strlen(IOTX_LINKKIT_KEY_UTC), cJSON_Invalid, &lite_item_utc);
dm_utils_json_object_item(&lite, IOTX_LINKKIT_KEY_RRPCID, strlen(IOTX_LINKKIT_KEY_RRPCID), cJSON_Invalid,
&lite_item_rrpcid);
dm_utils_json_object_item(&lite, IOTX_LINKKIT_KEY_TOPO, strlen(IOTX_LINKKIT_KEY_TOPO), cJSON_Invalid,
&lite_item_topo);
dm_utils_json_object_item(&lite, IOTX_LINKKIT_KEY_PRODUCT_KEY, strlen(IOTX_LINKKIT_KEY_PRODUCT_KEY), cJSON_Invalid,
&lite_item_pk);
dm_utils_json_object_item(&lite, IOTX_LINKKIT_KEY_TIME, strlen(IOTX_LINKKIT_KEY_TIME), cJSON_Invalid,
&lite_item_time);
dm_utils_json_object_item(&lite, IOTX_LINKKIT_KEY_VERSION, strlen(IOTX_LINKKIT_KEY_VERSION), cJSON_Invalid,
&lite_item_version);
dm_utils_json_object_item(&lite, IOTX_LINKKIT_KEY_CONFIG_ID, strlen(IOTX_LINKKIT_KEY_CONFIG_ID), cJSON_Invalid,
&lite_item_configid);
dm_utils_json_object_item(&lite, IOTX_LINKKIT_KEY_CONFIG_SIZE, strlen(IOTX_LINKKIT_KEY_CONFIG_SIZE), cJSON_Invalid,
&lite_item_configsize);
dm_utils_json_object_item(&lite, IOTX_LINKKIT_KEY_GET_TYPE, strlen(IOTX_LINKKIT_KEY_GET_TYPE), cJSON_Invalid,
&lite_item_gettype);
dm_utils_json_object_item(&lite, IOTX_LINKKIT_KEY_SIGN, strlen(IOTX_LINKKIT_KEY_SIGN), cJSON_Invalid,
&lite_item_sign);
dm_utils_json_object_item(&lite, IOTX_LINKKIT_KEY_SIGN_METHOD, strlen(IOTX_LINKKIT_KEY_SIGN_METHOD), cJSON_Invalid,
&lite_item_signmethod);
dm_utils_json_object_item(&lite, IOTX_LINKKIT_KEY_URL, strlen(IOTX_LINKKIT_KEY_URL), cJSON_Invalid,
&lite_item_url);
}
switch (type) {
case IOTX_DM_EVENT_CLOUD_CONNECTED: {
callback = iotx_event_callback(ITE_CONNECT_SUCC);
if (callback) {
((int (*)(void))callback)();
}
}
break;
case IOTX_DM_EVENT_CLOUD_DISCONNECT: {
//callback = iotx_event_callback(ITE_DISCONNECTED);
if (callback) {
((int (*)(void))callback)();
}
}
break;
case IOTX_DM_EVENT_INITIALIZED: {
if (payload == NULL || lite_item_devid.type != cJSON_Number) {
return;
}
dm_log_debug("Current Devid: %d", lite_item_devid.value_int);
//callback = iotx_event_callback(ITE_INITIALIZE_COMPLETED);
if (callback) {
((int (*)(const int))callback)(lite_item_devid.value_int);
}
}
break;
case IOTX_DM_EVENT_MODEL_DOWN_RAW: {
int raw_data_len = 0;
unsigned char *raw_data = NULL;
if (payload == NULL || lite_item_devid.type != cJSON_Number || lite_item_payload.type != cJSON_String) {
return;
}
dm_log_debug("Current Devid: %d", lite_item_devid.value_int);
dm_log_debug("Current Raw Data: %.*s", lite_item_payload.value_length, lite_item_payload.value);
raw_data_len = lite_item_payload.value_length / 2;
raw_data = IMPL_LINKKIT_MALLOC(raw_data_len);
if (raw_data == NULL) {
dm_log_err("No Enough Memory");
return;
}
LITE_hexstr_convert(lite_item_payload.value, lite_item_payload.value_length, raw_data, raw_data_len);
HEXDUMP_DEBUG(raw_data, raw_data_len);
//callback = iotx_event_callback(ITE_RAWDATA_ARRIVED);
if (callback) {
((int (*)(const int, const unsigned char *, const int))callback)(lite_item_devid.value_int, raw_data, raw_data_len);
}
IMPL_LINKKIT_FREE(raw_data);
}
break;
case IOTX_DM_EVENT_MODEL_UP_RAW_REPLY: {
int raw_data_len = 0;
unsigned char *raw_data = NULL;
if (payload == NULL || lite_item_devid.type != cJSON_Number || lite_item_payload.type != cJSON_String) {
return;
}
dm_log_debug("Current Devid: %d", lite_item_devid.value_int);
dm_log_debug("Current Raw Data: %.*s", lite_item_payload.value_length, lite_item_payload.value);
raw_data_len = lite_item_payload.value_length / 2;
raw_data = IMPL_LINKKIT_MALLOC(raw_data_len);
if (raw_data == NULL) {
dm_log_err("No Enough Memory");
return;
}
memset(raw_data, 0, raw_data_len);
LITE_hexstr_convert(lite_item_payload.value, lite_item_payload.value_length, raw_data, raw_data_len);
HEXDUMP_DEBUG(raw_data, raw_data_len);
//callback = iotx_event_callback(ITE_RAWDATA_ARRIVED);
if (callback) {
((int (*)(const int, const unsigned char *, const int))callback)(lite_item_devid.value_int, raw_data, raw_data_len);
}
IMPL_LINKKIT_FREE(raw_data);
}
break;
#if !defined(DEVICE_MODEL_RAWDATA_SOLO)
case IOTX_DM_EVENT_THING_SERVICE_REQUEST: {
int response_len = 0;
char *request = NULL, *response = NULL;
uintptr_t property_get_ctx_num = 0;
void *property_get_ctx = NULL;
if (payload == NULL || lite_item_id.type != cJSON_String || lite_item_devid.type != cJSON_Number ||
lite_item_serviceid.type != cJSON_String || lite_item_payload.type != cJSON_Object) {
return;
}
dm_log_debug("Current Id: %.*s", lite_item_id.value_length, lite_item_id.value);
dm_log_debug("Current Devid: %d", lite_item_devid.value_int);
dm_log_debug("Current ServiceID: %.*s", lite_item_serviceid.value_length, lite_item_serviceid.value);
dm_log_debug("Current Payload: %.*s", lite_item_payload.value_length, lite_item_payload.value);
dm_log_debug("Current Ctx: %.*s", lite_item_ctx.value_length, lite_item_ctx.value);
LITE_hexstr_convert(lite_item_ctx.value, lite_item_ctx.value_length, (unsigned char *)&property_get_ctx_num,
sizeof(uintptr_t));
property_get_ctx = (void *)property_get_ctx_num;
request = IMPL_LINKKIT_MALLOC(lite_item_payload.value_length + 1);
if (request == NULL) {
dm_log_err("Not Enough Memory");
return;
}
memset(request, 0, lite_item_payload.value_length + 1);
memcpy(request, lite_item_payload.value, lite_item_payload.value_length);
//callback = iotx_event_callback(ITE_SERVICE_REQUEST);
if (callback) {
res = ((int (*)(const int, const char *, const int, const char *, const int, char **,
int *))callback)(lite_item_devid.value_int, lite_item_serviceid.value,
lite_item_serviceid.value_length, request, lite_item_payload.value_length, &response, &response_len);
if (response != NULL && response_len > 0) {
/* service response exist */
iotx_dm_error_code_t code = (res == 0) ? (IOTX_DM_ERR_CODE_SUCCESS) : (IOTX_DM_ERR_CODE_REQUEST_ERROR);
iotx_dm_send_service_response(lite_item_devid.value_int, lite_item_id.value, lite_item_id.value_length, code,
lite_item_serviceid.value,
lite_item_serviceid.value_length,
response, response_len, property_get_ctx);
HAL_Free(response);
}
}
#ifdef ALCS_ENABLED
if (property_get_ctx) {
dm_server_free_context(property_get_ctx);
}
#endif
IMPL_LINKKIT_FREE(request);
}
break;
case IOTX_DM_EVENT_PROPERTY_SET: {
char *property_payload = NULL;
if (payload == NULL || lite_item_devid.type != cJSON_Number || lite_item_payload.type != cJSON_Object) {
return;
}
dm_log_debug("Current Devid: %d", lite_item_devid.value_int);
dm_log_debug("Current Payload: %.*s", lite_item_payload.value_length, lite_item_payload.value);
property_payload = IMPL_LINKKIT_MALLOC(lite_item_payload.value_length + 1);
if (property_payload == NULL) {
dm_log_err("No Enough Memory");
return;
}
memset(property_payload, 0, lite_item_payload.value_length + 1);
memcpy(property_payload, lite_item_payload.value, lite_item_payload.value_length);
#ifdef LOG_REPORT_TO_CLOUD
if (SUCCESS_RETURN == check_target_msg(msg_id.value, msg_id.value_length)) {
report_sample = 1;
send_permance_info(msg_id.value, msg_id.value_length, "3", 1);
}
#endif
//callback = iotx_event_callback(ITE_PROPERTY_SET);
if (callback) {
((int (*)(const int, const char *, const int))callback)(lite_item_devid.value_int, property_payload,
lite_item_payload.value_length);
}
#ifdef LOG_REPORT_TO_CLOUD
if (1 == report_sample) {
send_permance_info(NULL, 0, "5", 2);
report_sample = 0;
}
#endif
IMPL_LINKKIT_FREE(property_payload);
}
break;
#ifdef DEVICE_MODEL_SHADOW
case IOTX_DM_EVENT_PROPERTY_DESIRED_GET_REPLY: {
char *property_data = NULL;
lite_cjson_t lite_item_data;
memset(&lite_item_data, 0, sizeof(lite_cjson_t));
dm_utils_json_object_item(&lite, IOTX_LINKKIT_KEY_DATA, strlen(IOTX_LINKKIT_KEY_DATA), cJSON_Invalid,
&lite_item_data);
if (payload == NULL || lite_item_data.type != cJSON_Object) {
return;
}
dm_log_debug("Current Data: %.*s", lite_item_data.value_length, lite_item_data.value);
property_data = IMPL_LINKKIT_MALLOC(lite_item_data.value_length + 1);
if (property_data == NULL) {
dm_log_err("No Enough Memory");
return;
}
memset(property_data, 0, lite_item_data.value_length + 1);
memcpy(property_data, lite_item_data.value, lite_item_data.value_length);
//callback = iotx_event_callback(ITE_PROPERTY_DESIRED_GET_REPLY);
if (callback) {
((int (*)(const char *, const int))callback)(property_data,
lite_item_data.value_length);
}
IMPL_LINKKIT_FREE(property_data);
}
break;
#endif
case IOTX_DM_EVENT_PROPERTY_GET: {
int response_len = 0;
char *request = NULL, *response = NULL;
uintptr_t property_get_ctx_num = 0;
void *property_get_ctx = NULL;
if (payload == NULL || lite_item_id.type != cJSON_String || lite_item_devid.type != cJSON_Number ||
lite_item_payload.type != cJSON_Array) {
return;
}
dm_log_debug("Current Id: %.*s", lite_item_id.value_length, lite_item_id.value);
dm_log_debug("Current Devid: %d", lite_item_devid.value_int);
dm_log_debug("Current Payload: %.*s", lite_item_payload.value_length, lite_item_payload.value);
dm_log_debug("Current Ctx: %.*s", lite_item_ctx.value_length, lite_item_ctx.value);
LITE_hexstr_convert(lite_item_ctx.value, lite_item_ctx.value_length, (unsigned char *)&property_get_ctx_num,
sizeof(uintptr_t));
property_get_ctx = (void *)property_get_ctx_num;
dm_log_debug("property_get_ctx_num: %0x016llX", (unsigned int)property_get_ctx_num);
dm_log_debug("property_get_ctx: %p", property_get_ctx);
request = IMPL_LINKKIT_MALLOC(lite_item_payload.value_length + 1);
if (request == NULL) {
dm_log_err("No Enough Memory");
return;
}
memset(request, 0, lite_item_payload.value_length + 1);
memcpy(request, lite_item_payload.value, lite_item_payload.value_length);
//callback = iotx_event_callback(ITE_PROPERTY_GET);
if (callback) {
res = ((int (*)(const int, const char *, const int, char **, int *))callback)(lite_item_devid.value_int, request,
lite_item_payload.value_length, &response, &response_len);
if (response != NULL && response_len > 0) {
/* property get response exist */
iotx_dm_error_code_t code = (res == 0) ? (IOTX_DM_ERR_CODE_SUCCESS) : (IOTX_DM_ERR_CODE_REQUEST_ERROR);
iotx_dm_send_property_get_response(lite_item_devid.value_int, lite_item_id.value, lite_item_id.value_length, code,
response, response_len, property_get_ctx);
HAL_Free(response);
}
}
IMPL_LINKKIT_FREE(request);
}
break;
case IOTX_DM_EVENT_EVENT_PROPERTY_POST_REPLY:
case IOTX_DM_EVENT_DEVICEINFO_UPDATE_REPLY:
#ifdef DEVICE_MODEL_SHADOW
case IOTX_DM_EVENT_PROPERTY_DESIRED_DELETE_REPLY:
#endif
case IOTX_DM_EVENT_DEVICEINFO_DELETE_REPLY: {
char *user_payload = NULL;
int user_payload_length = 0;
if (payload == NULL || lite_item_id.type != cJSON_Number || lite_item_code.type != cJSON_Number
|| lite_item_devid.type != cJSON_Number) {
return;
}
dm_log_debug("Current Id: %d", lite_item_id.value_int);
dm_log_debug("Current Code: %d", lite_item_code.value_int);
dm_log_debug("Current Devid: %d", lite_item_devid.value_int);
if (lite_item_payload.type == cJSON_Object && lite_item_payload.value_length > 0) {
user_payload = IMPL_LINKKIT_MALLOC(lite_item_payload.value_length + 1);
if (user_payload == NULL) {
dm_log_err("No Enough Memory");
return;
}
memset(user_payload, 0, lite_item_payload.value_length + 1);
memcpy(user_payload, lite_item_payload.value, lite_item_payload.value_length);
user_payload_length = lite_item_payload.value_length;
}
//callback = iotx_event_callback(ITE_REPORT_REPLY);
if (callback) {
((int (*)(const int, const int, const int, const char *, const int))callback)(lite_item_devid.value_int,
lite_item_id.value_int, lite_item_code.value_int, user_payload,
user_payload_length);
}
if (user_payload) {
IMPL_LINKKIT_FREE(user_payload);
}
}
break;
case IOTX_DM_EVENT_EVENT_SPECIFIC_POST_REPLY: {
char *user_eventid = NULL;
char *user_payload = NULL;
if (payload == NULL || lite_item_id.type != cJSON_Number || lite_item_code.type != cJSON_Number ||
lite_item_devid.type != cJSON_Number || lite_item_eventid.type != cJSON_String
|| lite_item_payload.type != cJSON_String) {
return;
}
dm_log_debug("Current Id: %d", lite_item_id.value_int);
dm_log_debug("Current Code: %d", lite_item_code.value_int);
dm_log_debug("Current Devid: %d", lite_item_devid.value_int);
dm_log_debug("Current EventID: %.*s", lite_item_eventid.value_length, lite_item_eventid.value);
dm_log_debug("Current Message: %.*s", lite_item_payload.value_length, lite_item_payload.value);
user_eventid = IMPL_LINKKIT_MALLOC(lite_item_eventid.value_length + 1);
if (user_eventid == NULL) {
dm_log_err("Not Enough Memory");
return;
}
memset(user_eventid, 0, lite_item_eventid.value_length + 1);
memcpy(user_eventid, lite_item_eventid.value, lite_item_eventid.value_length);
user_payload = IMPL_LINKKIT_MALLOC(lite_item_payload.value_length + 1);
if (user_payload == NULL) {
dm_log_err("Not Enough Memory");
IMPL_LINKKIT_FREE(user_eventid);
return;
}
memset(user_payload, 0, lite_item_payload.value_length + 1);
memcpy(user_payload, lite_item_payload.value, lite_item_payload.value_length);
//callback = iotx_event_callback(ITE_TRIGGER_EVENT_REPLY);
if (callback) {
((int (*)(const int, const int, const int, const char *, const int, const char *,
const int))callback)(lite_item_devid.value_int,
lite_item_id.value_int, lite_item_code.value_int,
user_eventid, lite_item_eventid.value_length, user_payload, lite_item_payload.value_length);
}
IMPL_LINKKIT_FREE(user_eventid);
IMPL_LINKKIT_FREE(user_payload);
}
break;
case IOTX_DM_EVENT_NTP_RESPONSE: {
char *utc_payload = NULL;
if (payload == NULL || lite_item_utc.type != cJSON_String) {
return;
}
dm_log_debug("Current UTC: %.*s", lite_item_utc.value_length, lite_item_utc.value);
utc_payload = IMPL_LINKKIT_MALLOC(lite_item_utc.value_length + 1);
if (utc_payload == NULL) {
dm_log_err("Not Enough Memory");
return;
}
memset(utc_payload, 0, lite_item_utc.value_length + 1);
memcpy(utc_payload, lite_item_utc.value, lite_item_utc.value_length);
//callback = iotx_event_callback(ITE_TIMESTAMP_REPLY);
if (callback) {
((int (*)(const char *))callback)(utc_payload);
}
IMPL_LINKKIT_FREE(utc_payload);
}
break;
case IOTX_DM_EVENT_RRPC_REQUEST: {
int rrpc_response_len = 0;
char *rrpc_request = NULL, *rrpc_response = NULL;
if (payload == NULL || lite_item_id.type != cJSON_String || lite_item_devid.type != cJSON_Number ||
lite_item_serviceid.type != cJSON_String || lite_item_rrpcid.type != cJSON_String
|| lite_item_payload.type != cJSON_Object) {
return;
}
dm_log_debug("Current Id: %.*s", lite_item_id.value_length, lite_item_id.value);
dm_log_debug("Current Devid: %d", lite_item_devid.value_int);
dm_log_debug("Current ServiceID: %.*s", lite_item_serviceid.value_length, lite_item_serviceid.value);
dm_log_debug("Current RRPC ID: %.*s", lite_item_rrpcid.value_length, lite_item_rrpcid.value);
dm_log_debug("Current Payload: %.*s", lite_item_payload.value_length, lite_item_payload.value);
rrpc_request = IMPL_LINKKIT_MALLOC(lite_item_payload.value_length + 1);
if (rrpc_request == NULL) {
dm_log_err("Not Enough Memory");
return;
}
memset(rrpc_request, 0, lite_item_payload.value_length + 1);
memcpy(rrpc_request, lite_item_payload.value, lite_item_payload.value_length);
//callback = iotx_event_callback(ITE_SERVICE_REQUEST);
if (callback) {
res = ((int (*)(const int, const char *, const int, const char *, const int, char **,
int *))callback)(lite_item_devid.value_int, lite_item_serviceid.value,
lite_item_serviceid.value_length,
rrpc_request, lite_item_payload.value_length, &rrpc_response, &rrpc_response_len);
if (rrpc_response != NULL && rrpc_response_len > 0) {
iotx_dm_error_code_t code = (res == 0) ? (IOTX_DM_ERR_CODE_SUCCESS) : (IOTX_DM_ERR_CODE_REQUEST_ERROR);
iotx_dm_send_rrpc_response(lite_item_devid.value_int, lite_item_id.value, lite_item_id.value_length, code,
lite_item_rrpcid.value,
lite_item_rrpcid.value_length,
rrpc_response, rrpc_response_len);
HAL_Free(rrpc_response);
}
}
IMPL_LINKKIT_FREE(rrpc_request);
}
break;
#endif
case IOTX_DM_EVENT_FOTA_NEW_FIRMWARE: {
char *version = NULL;
if (payload == NULL || lite_item_version.type != cJSON_String) {
return;
}
dm_log_debug("Current Firmware Version: %.*s", lite_item_version.value_length, lite_item_version.value);
version = IMPL_LINKKIT_MALLOC(lite_item_version.value_length + 1);
if (version == NULL) {
return;
}
memset(version, 0, lite_item_version.value_length + 1);
memcpy(version, lite_item_version.value, lite_item_version.value_length);
//callback = iotx_event_callback(ITE_FOTA);
if (callback) {
((int (*)(const int, const char *))callback)(0, version);
}
if (version) {
IMPL_LINKKIT_FREE(version);
}
}
break;
case IOTX_DM_EVENT_COTA_NEW_CONFIG: {
char *config_id = NULL, *get_type = NULL, *sign = NULL, *sign_method = NULL, *url = NULL;
if (payload == NULL || lite_item_configid.type != cJSON_String || lite_item_configsize.type != cJSON_Number ||
lite_item_gettype.type != cJSON_String || lite_item_sign.type != cJSON_String
|| lite_item_signmethod.type != cJSON_String ||
lite_item_url.type != cJSON_String) {
return;
}
dm_log_debug("Current Config ID: %.*s", lite_item_configid.value_length, lite_item_configid.value);
dm_log_debug("Current Config Size: %d", lite_item_configsize.value_int);
dm_log_debug("Current Get Type: %.*s", lite_item_gettype.value_length, lite_item_gettype.value);
dm_log_debug("Current Sign: %.*s", lite_item_sign.value_length, lite_item_sign.value);
dm_log_debug("Current Sign Method: %.*s", lite_item_signmethod.value_length, lite_item_signmethod.value);
dm_log_debug("Current URL: %.*s", lite_item_url.value_length, lite_item_url.value);
_impl_copy(lite_item_configid.value, lite_item_configid.value_length, (void **)&config_id,
lite_item_configid.value_length + 1);
_impl_copy(lite_item_gettype.value, lite_item_gettype.value_length, (void **)&get_type,
lite_item_gettype.value_length + 1);
_impl_copy(lite_item_sign.value, lite_item_sign.value_length, (void **)&sign, lite_item_sign.value_length + 1);
_impl_copy(lite_item_signmethod.value, lite_item_signmethod.value_length, (void **)&sign_method,
lite_item_signmethod.value_length + 1);
_impl_copy(lite_item_url.value, lite_item_url.value_length, (void **)&url, lite_item_url.value_length + 1);
if (config_id == NULL || get_type == NULL || sign == NULL || sign_method == NULL || url == NULL) {
if (config_id) {
IMPL_LINKKIT_FREE(config_id);
}
if (get_type) {
IMPL_LINKKIT_FREE(get_type);
}
if (sign) {
IMPL_LINKKIT_FREE(sign);
}
if (sign_method) {
IMPL_LINKKIT_FREE(sign_method);
}
if (url) {
IMPL_LINKKIT_FREE(url);
}
return;
}
//callback = iotx_event_callback(ITE_COTA);
if (callback) {
((int (*)(const int, const char *, int, const char *, const char *, const char *, const char *))callback)(0, config_id,
lite_item_configsize.value_int, get_type, sign, sign_method, url);
}
if (config_id) {
IMPL_LINKKIT_FREE(config_id);
}
if (get_type) {
IMPL_LINKKIT_FREE(get_type);
}
if (sign) {
IMPL_LINKKIT_FREE(sign);
}
if (sign_method) {
IMPL_LINKKIT_FREE(sign_method);
}
if (url) {
IMPL_LINKKIT_FREE(url);
}
}
break;
#ifdef 1//DEVICE_MODEL_GATEWAY
case IOTX_DM_EVENT_TOPO_GET_REPLY: {
char *topo_list = NULL;
if (payload == NULL || lite_item_id.type != cJSON_Number || lite_item_devid.type != cJSON_Number ||
lite_item_code.type != cJSON_Number || lite_item_topo.type != cJSON_Array) {
return;
}
dm_log_debug("Current Id: %d", lite_item_id.value_int);
dm_log_debug("Current Devid: %d", lite_item_devid.value_int);
dm_log_debug("Current Code: %d", lite_item_code.value_int);
dm_log_debug("Current Topo List: %.*s", lite_item_topo.value_length, lite_item_topo.value);
topo_list = IMPL_LINKKIT_MALLOC(lite_item_topo.value_length + 1);
if (topo_list == NULL) {
dm_log_err("Not Enough Memory");
return;
}
memset(topo_list, 0, lite_item_topo.value_length + 1);
memcpy(topo_list, lite_item_topo.value, lite_item_topo.value_length);
//callback = iotx_event_callback(ITE_TOPOLIST_REPLY);
if (callback) {
((int (*)(const int, const int, const int, const char *, const int))callback)(lite_item_devid.value_int,
lite_item_id.value_int,
lite_item_code.value_int, topo_list, lite_item_topo.value_length);
}
IMPL_LINKKIT_FREE(topo_list);
}
break;
case IOTX_DM_EVENT_TOPO_DELETE_REPLY:
case IOTX_DM_EVENT_TOPO_ADD_REPLY:
case IOTX_DM_EVENT_SUBDEV_REGISTER_REPLY:
case IOTX_DM_EVENT_COMBINE_LOGIN_REPLY:
case IOTX_DM_EVENT_COMBINE_LOGOUT_REPLY: {
if (payload == NULL || lite_item_id.type != cJSON_Number || lite_item_devid.type != cJSON_Number ||
lite_item_code.type != cJSON_Number) {
return;
}
dm_log_debug("Current Id: %d", lite_item_id.value_int);
dm_log_debug("Current Code: %d", lite_item_code.value_int);
dm_log_debug("Current Devid: %d", lite_item_devid.value_int);
_iotx_linkkit_upstream_mutex_lock();
_iotx_linkkit_upstream_callback_remove(lite_item_id.value_int, lite_item_code.value_int);
_iotx_linkkit_upstream_mutex_unlock();
}
break;
case IOTX_DM_EVENT_GATEWAY_PERMIT: {
char *product_key = "";
if (payload == NULL || lite_item_time.type != cJSON_Number) {
return;
}
dm_log_debug("Current Time: %d", lite_item_time.value_int);
if (lite_item_pk.type == cJSON_String) {
dm_log_debug("Current Product Key: %.*s", lite_item_pk.value_length, lite_item_pk.value);
product_key = IMPL_LINKKIT_MALLOC(lite_item_pk.value_length + 1);
if (product_key == NULL) {
dm_log_err("Not Enough Memory");
return;
}
memset(product_key, 0, lite_item_pk.value_length + 1);
memcpy(product_key, lite_item_pk.value, lite_item_pk.value_length);
}
//callback = iotx_event_callback(ITE_PERMIT_JOIN);
if (callback) {
((int (*)(const char *, int))callback)((const char *)product_key, (const int)lite_item_time.value_int);
}
if (lite_item_pk.type == cJSON_String) {
IMPL_LINKKIT_FREE(product_key);
}
}
break;
#endif
default: {
}
break;
}
#endif
}
int kk_init_dmproc(){
......
......@@ -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) {
......
......@@ -7,9 +7,15 @@
#include "cJSON.h"
#include <time.h>
extern int g_timezone;
extern sqlite3 *g_kk_pDb;
static void kk_scene_send_action_msg(kk_scene_action_info_t *pInfo);
static int kk_scene_update_starttime(kk_scene_timer_list_t *pInfo,int starttime,int current);
static time_t kk_scene_creat_timer_starttime(int week,int starttime,time_t current);
static int kk_scene_parse_repeatday(cJSON *repeatday);
typedef struct {
void *mutex;
......@@ -61,6 +67,12 @@ typedef enum{
DB_SCENEACTION_GWDEVICECODE,
};
typedef enum{
DB_SCENETIMER_WEEK = 0,
DB_SCENETIMER_TIME,
DB_SCENETIMER_SCENEID,
};
static kk_scene_action_t *p_kk_scene_action = NULL;
......@@ -198,6 +210,20 @@ static int _kk_scene_db_init(void)
if (sqlite3_exec(ctx->pDb, pSceneActionTable, NULL, NULL, &pcErr) != SQLITE_OK)
{
ERROR_PRINT("Error creating table (%s)\n", pcErr);
sqlite3_free(pcErr);
//eUtils_LockUnlock(&sLock);
_kk_scene_unlock();
return FAIL_RETURN;
}
const char *pSceneTimerTable = "CREATE TABLE IF NOT EXISTS SceneTimerInfo( \
week INTEGER, \
time INTEGER, \
sceneId varchar(255))";
if (sqlite3_exec(ctx->pDb, pSceneTimerTable, NULL, NULL, &pcErr) != SQLITE_OK)
{
ERROR_PRINT("Error creating table (%s)\n", pcErr);
sqlite3_free(pcErr);
......@@ -250,17 +276,15 @@ static int kk_scene_timer_load(void)
kk_scene_ctx_t *ctx = _kk_scene_get_ctx();
sqlite3_stmt *stmt;
char *sceneId = NULL;
char *sqlCmd = "select * from SceneConditionInfo WHERE type = 'timeRange'";
char *sqlCmd = "select * from SceneTimerInfo WHERE type = 'timeRange'";
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
sceneId = sqlite3_column_text(stmt, DB_SCENECONDITION_SCENEID);
sceneId = sqlite3_column_text(stmt, DB_SCENETIMER_SCENEID);
if(kk_scene_check_able(sceneId) == SUCCESS_RETURN){
int starttime = sqlite3_column_int(stmt, DB_SCENECONDITION_STARTTIME);
int endtime = sqlite3_column_int(stmt, DB_SCENECONDITION_ENDTIME);
int repeatday = sqlite3_column_int(stmt, DB_SCENECONDITION_REPEATDAY);
kk_scene_push_timer_info(starttime,endtime,repeatday,sceneId);
int starttime = sqlite3_column_int(stmt, DB_SCENETIMER_TIME);
int repeatday = sqlite3_column_int(stmt, DB_SCENETIMER_WEEK);
kk_scene_push_timer_info(starttime,repeatday,sceneId);
}
}
sqlite3_finalize(stmt);
......@@ -322,11 +346,9 @@ void *kk_scene_yield(void *args)
/*******定时模式**********/
scene_timer_list = p_scene_timer_list;
while(scene_timer_list){
INFO_PRINT("--------scene_timer_list->starttime:%d\n",scene_timer_list->starttime);
INFO_PRINT("--------current_time %d\n",current_time);
INFO_PRINT("--------scene_timer_list->end:%d\n",scene_timer_list->endtime);
if(current_time >= scene_timer_list->starttime && \
current_time <= scene_timer_list->endtime){
//INFO_PRINT("scene_timer_list->starttime:%d\n",scene_timer_list->starttime);
//INFO_PRINT("current_time %d\n",current_time);
if(scene_timer_list->starttime != 0 && current_time >= scene_timer_list->starttime){
kk_scene_execute_action(scene_timer_list->sceneId);
kk_scene_update_starttime(scene_timer_list,scene_timer_list->starttime,current_time);
}
......@@ -474,6 +496,35 @@ static int kk_scene_insert_scene_condition(const char* type,int startTime,int en
}
static int kk_scene_insert_scene_timer(char weekflag,int startTime,const char* sceneId)
{
int res = 0;
kk_scene_ctx_t *ctx = _kk_scene_get_ctx();
char *sqlCmd = NULL;
char *zErrMsg = 0;
const char *insertCmd = "insert into SceneTimerInfo (week,time,sceneId) \
values ('%d','%d','%s');";
_kk_scene_lock();
sqlCmd = sqlite3_mprintf(insertCmd,weekflag,startTime,sceneId);
res = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( res != SQLITE_OK ){
ERROR_PRINT("SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
sqlite3_free(sqlCmd);
_kk_scene_unlock();
return FAIL_RETURN;
}
sqlite3_free(sqlCmd);
_kk_scene_unlock();
return SUCCESS_RETURN;
}
static int kk_scene_action_info_add(kk_scene_action_info_ex_t **head,kk_scene_action_detail_t detail)
{
int len;
......@@ -779,6 +830,7 @@ static int kk_scene_parse_trigger_detail(const char *type,const cJSON *item,cons
int kk_scene_parse_scene_trigger(const cJSON* str,const char *sceneId)
{
int res = 0;
int weekflag = 0;
if(str == NULL || sceneId == NULL){
return INVALID_PARAMETER;
}
......@@ -791,11 +843,24 @@ int kk_scene_parse_scene_trigger(const cJSON* str,const char *sceneId)
while(item != NULL){
cJSON *type = cJSON_GetObjectItem(item,MSG_SCENE_TYPE);
if(type == NULL) return FAIL_RETURN;
if(!strcmp("trigger/thing/property",type->valuestring)){
res = kk_scene_parse_trigger_detail(type->valuestring,item,sceneId);
if(res != SUCCESS_RETURN){
ERROR_PRINT("kk_scene_parse_scene_trigger fail!!!\n");
return res;
}
}
else if(!strcmp("trigger/timing",type->valuestring)){
cJSON *week = cJSON_GetObjectItem(item,MSG_SCENE_WEEK);
if(week == NULL) return FAIL_RETURN;
weekflag = kk_scene_parse_repeatday(week);
cJSON *time = cJSON_GetObjectItem(item,MSG_SCENE_TIME);
if(time == NULL) return FAIL_RETURN;
time_t current = HAL_GetTime();
time_t newStart = kk_scene_creat_timer_starttime(weekflag,atoi(time->valuestring),current);
kk_scene_insert_scene_timer(newStart,weekflag,sceneId);
kk_scene_push_timer_info(newStart,weekflag,sceneId);
}
item = item->next;
}
INFO_PRINT("kk_scene_parse_scene_trigger success!!!\n");
......@@ -852,7 +917,7 @@ void kk_scene_remove_timer_info(char *sceneId)
_kk_scene_unlock();
}
int kk_scene_push_timer_info(int starttime,int endtime,int repeatday,char *sceneId)
int kk_scene_push_timer_info(time_t starttime,int repeatday,char *sceneId)
{
kk_scene_timer_list_t *ptr = NULL,*ptemp = NULL;
if(sceneId == NULL){
......@@ -871,7 +936,6 @@ int kk_scene_push_timer_info(int starttime,int endtime,int repeatday,char *scene
}
memset(ptr,0x0,sizeof(kk_scene_timer_list_t));
ptr->starttime = starttime;
ptr->endtime = endtime;
ptr->repeatday = repeatday;
memcpy(ptr->sceneId,sceneId,strlen(sceneId));
if(p_scene_timer_list == NULL){
......@@ -907,12 +971,10 @@ int kk_scene_parse_scene_condition(const cJSON* str,const char *sceneId)
if(startTime == NULL) return FAIL_RETURN;
cJSON *endTime = cJSON_GetObjectItem(item,MSG_SCENE_ENDTIME);
if(endTime == NULL) return FAIL_RETURN;
//cJSON *crossday = cJSON_GetObjectItem(item,MSG_SCENE_CROSSDAY);
//if(crossday == NULL) return FAIL_RETURN;
cJSON *repeatday = cJSON_GetObjectItem(item,MSG_SCENE_REPEATDAYS);
if(repeatday == NULL) return FAIL_RETURN;
weekflag = kk_scene_parse_repeatday(repeatday);
kk_scene_push_timer_info(startTime->valueint,endTime->valueint,weekflag,sceneId);
//kk_scene_push_timer_info(startTime->valueint,endTime->valueint,weekflag,sceneId);
res = kk_scene_insert_scene_condition(type->valuestring,startTime->valueint,endTime->valueint,
0,weekflag,sceneId);
if(res != SUCCESS_RETURN){
......@@ -920,7 +982,7 @@ int kk_scene_parse_scene_condition(const cJSON* str,const char *sceneId)
return res;
}
}
else if(!strcmp("condition",type->valuestring)){
else if(!strcmp("trigger/thing/property",type->valuestring)){
kk_scene_parse_trigger_detail(type->valuestring,item,sceneId);
}
else{
......@@ -1102,7 +1164,6 @@ static int kk_scene_update_starttime(kk_scene_timer_list_t *pInfo,int starttime,
/*only support once*/
if(pInfo->repeatday == 0){
pInfo->starttime = 0;
pInfo->endtime = 0;
kk_scene_update_scene_enable(0,pInfo->sceneId);
return SUCCESS_RETURN;
}else{
......@@ -1116,7 +1177,6 @@ static int kk_scene_update_starttime(kk_scene_timer_list_t *pInfo,int starttime,
}
if(curWeek & pInfo->repeatday){
pInfo->starttime = pInfo->starttime + 86400*i;
pInfo->endtime = pInfo->endtime + 86400*i;
return SUCCESS_RETURN;
}
}
......@@ -1131,19 +1191,54 @@ static time_t kk_scene_creat_new_starttime(time_t starttime,time_t current)
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;
printf("[%d]startTime :%d\n",__LINE__,starttime);
hour = starttime/3600;
min = starttime%3600/60;
printf("[hour:%d][min:%d]\n",hour,min);
struct tm *c = localtime(&current);
c->tm_hour = hour;
c->tm_min = min;
c->tm_sec = sec;
c->tm_sec = 0;
newTime = mktime(c);
INFO_PRINT("kk_scene_creat_new_starttime:%ld\n",newTime);
return newTime;
}
static time_t kk_scene_creat_timer_starttime(int week,int starttime,time_t current)
{
int hour,min,sec;
time_t newTime = 0;
char curWeek = 0;
int startNew = 0;
int i = 0;
curWeek = kk_scene_date_to_week(current);
startNew = starttime + g_timezone*3600;
startNew = (startNew - 86400) >= 0?(startNew - 86400) : startNew;
INFO_PRINT("kk_scene_creat_timer_starttime:%d\n",startNew);
/*today is not repeat day*/
if((week > 0)&&(!(week &(1<<(curWeek-1)))))
{
for(i = 1; i < 8; i++){
if(curWeek == 0x40){ //0x40 ==>01000000 ,sunday
curWeek = curWeek>>6;
}
else{
curWeek = curWeek<<1;
}
if(curWeek & week){
newTime = current + 86400*i;
return kk_scene_creat_new_starttime(startNew,newTime);
}
}
}
else
{
return kk_scene_creat_new_starttime(startNew,current);
}
}
int kk_scene_check_trigger_condition(const char *sceneId)
{
int res = FAIL_RETURN;
......@@ -1216,7 +1311,12 @@ int kk_scene_check_condition(const char *sceneId)
repeatday = sqlite3_column_int(stmt, DB_SCENECONDITION_REPEATDAY);
startTime = sqlite3_column_int(stmt, DB_SCENECONDITION_STARTTIME);
endTime = sqlite3_column_int(stmt, DB_SCENECONDITION_ENDTIME);
crossDay = sqlite3_column_int(stmt, DB_SCENECONDITION_CROSSDAY);
//crossDay = sqlite3_column_int(stmt, DB_SCENECONDITION_CROSSDAY);
startTime = startTime + g_timezone*3600;
startTime = (startTime - 86400) >= 0?(startTime - 86400) : startTime;
endTime = endTime + g_timezone*3600;
endTime = (endTime - 86400) >= 0?(endTime - 86400) : endTime;
duration = endTime - startTime;
startTime_m = kk_scene_creat_new_starttime(startTime,current);
INFO_PRINT("current:%ld,startTime_m:%ld,repeatday:%d\n",current,startTime_m,repeatday);
......@@ -1249,12 +1349,12 @@ int kk_scene_check_condition(const char *sceneId)
}
else{
if(current >= startTime && current <= (startTime + duration)){
if(current >= startTime_m && current <= (startTime_m + duration)){
res = SUCCESS_RETURN;
}
else
{
INFO_PRINT("time not match current:%ld,startTime:%ld\n",current,startTime);
INFO_PRINT("time not match current:%ld,startTime_m:%ld\n",current,startTime_m);
}
}
}
......@@ -1475,6 +1575,7 @@ int kk_scene_execute_action(const char* sceneId)
int idx=0,num = 0;
sqlite3_stmt *stmt;
kk_scene_ctx_t *ctx = _kk_scene_get_ctx();
INFO_PRINT("[%s][%d] kk_scene_execute_action now!!!\n",__FUNCTION__,__LINE__);
sqlCmd = sqlite3_mprintf("select * from SceneActionInfo WHERE sceneId = '%s'",sceneId);
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
next:
......@@ -1504,6 +1605,7 @@ next:
}
}
sqlite3_finalize(stmt);
return res;
}
......
......@@ -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