Commit 965f71af authored by chen.weican's avatar chen.weican

【修改内容】1,增加场景对于LIGHT和CURTAIN设备类型的支持;2,增加CCU主机版本号定义;3,其他细节修改

【提交人】陈伟灿
parent 524d27d1
......@@ -50,6 +50,7 @@ static int mqtt_start(void)
//INFO_PRINT("i am send now\n");
//KK_MQTT_SendMsg(TOPIC,"hello my world",2);
}
//INFO_PRINT(" %s \n",testStr);
}
INFO_PRINT("MQTTAsync_destroy\n");
......
......@@ -264,6 +264,7 @@ int KK_MQTT_SendMsg(char *topicName,const char *payload)
pubmsg.qos = QOS;
pubmsg.retained = 0;
//cJSON_Minify(payload);
INFO_PRINT("mqtt send payload :%s.\n",payload);
if ((rc = MQTTAsync_sendMessage(s_Client, topicName, &pubmsg, &opts)) != MQTTASYNC_SUCCESS)
......
#ifndef _KK_CCU_VER_H_
#define _KK_CCU_VER_H_
#define KK_CCU_VERSION "1.1.0"
#endif
......@@ -27,7 +27,8 @@ typedef enum {
IPC_PLAT2MID,
IPC_UNDEF
} ipc_type;
#define MSG_COMMON_MSGID "msgId"
#define MSG_TYPE_STR "msgtype"
#define MSG_PRODUCT_TYPE_STR "productType"
#define MSG_PRODUCT_CODE_STR "productCode"
......
This diff is collapsed.
......@@ -28,7 +28,7 @@
#include <time.h>
#include <signal.h>
#include "kk_product.h"
//#include "iot_import.h"
#include "ccu_ver.h"
char g_product_type[PRODUCT_TYPE_LEN]={0};
char g_product_code[PRODUCT_CODE_LEN]={0};
......@@ -295,10 +295,9 @@ int HAL_GetDevice_Code(_OU_ char *device_code)
}
int HAL_GetVersion(_OU_ char *version)
{
char *ver = "test-1.0.0";
int len = strlen(ver);
int len = strlen(KK_CCU_VERSION);
memset(version, 0x0, VERSION_MAXLEN);
strncpy(version, ver, len);
strncpy(version, KK_CCU_VERSION, len);
version[len] = '\0';
return strlen(version);
}
......
......@@ -738,7 +738,7 @@ int dm_msg_thing_property_set_reply(char deviceCode[DEVICE_CODE_MAXLEN],char *pa
dm_msg_response(&request, &response, "{}", strlen("{}"), NULL);
return SUCCESS_RETURN;
}
int dm_msg_thing_event_post(const char *deviceCode, const char *identifier)
int dm_msg_thing_event_post(const char *deviceCode, const char *identifier,const char *msgId)
{
int res = 0;
int nums = 0;
......@@ -774,7 +774,13 @@ int dm_msg_thing_event_post(const char *deviceCode, const char *identifier)
ERROR_PRINT("dm_msg_thing_event_post failed\n");
return FAIL_RETURN;
}
dm_mgr_upstream_thing_event_post(node->devid, identifier, strlen(identifier), method, payload, strlen(payload));
if(msgId != NULL){
dm_mgr_upstream_thing_event_post_ex(node->devid, identifier, strlen(identifier), method, payload, strlen(payload),msgId);
}else
{
dm_mgr_upstream_thing_event_post(node->devid, identifier, strlen(identifier), method, payload, strlen(payload));
}
free(method);
method = NULL;
free(payload);
......
This diff is collapsed.
......@@ -573,76 +573,91 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *scen
int idx = 0;
int gw_support_scene = 0;
kk_tsl_data_t *property = NULL;
int k = 0,count = 0;
char typeArray[10][32] = {0};
if(productType == NULL){
ERROR_PRINT("ERROR [%s][%d]\n",__FUNCTION__,__LINE__);
return INVALID_PARAMETER;
}
sqlCmd = sqlite3_mprintf(searchCmd,productType); //switch jsut for test
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
//INFO_PRINT("total_column = %d\n", sqlite3_column_count(stmt));
while(sqlite3_step(stmt) == SQLITE_ROW){
pDeviceCode = sqlite3_column_text(stmt, DB_DEVICECODE);
res = dm_mgr_get_device_by_devicecode(pDeviceCode,&node);
if (res != SUCCESS_RETURN) {
continue;
}
if(kk_subDev_check_scene_support(node->fatherDeviceCode) == 1){
gw_support_scene = 1;
}
else{
gw_support_scene = 0;
}
if(!strcmp(productType,"switch")){
for(idx = 0; idx < node->dev_shadow->property_number; idx++){
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
if(property == NULL){
continue;
}
if(strstr(property->identifier,"PowerSwitch") != NULL){
if(gw_support_scene){
kk_scene_action_detail_t info = {0};
memcpy(info.deviceCode,node->deviceCode,strlen(node->deviceCode));
memcpy(info.propertyName,property->identifier,strlen(property->identifier));
memcpy(info.propertyValue,propertyValue,strlen(propertyValue));
info.epNum = 1;
info.delay = 0;
kk_scene_action_add(node->fatherDeviceCode,sceneId,info);
INFO_PRINT("kk_subDev_set_action_by_productType called!!!\n");
if(!strcmp(productType,"CURTAIN")){
memcpy(typeArray[0],"curtain",strlen("curtain"));
count = 1;
}
else if(!strcmp(productType,"LIGHT")){
memcpy(typeArray[0],"switch",strlen("switch"));
memcpy(typeArray[1],"light",strlen("light"));
count = 2;
}
else{
INFO_PRINT("kk_subDev_set_action_by_productType wrong type!!!\n");
}
for(k = 0; k < count; k++){
sqlCmd = sqlite3_mprintf(searchCmd,typeArray[k]); //curtain type
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
//INFO_PRINT("total_column = %d\n", sqlite3_column_count(stmt));
while(sqlite3_step(stmt) == SQLITE_ROW){
pDeviceCode = sqlite3_column_text(stmt, DB_DEVICECODE);
res = dm_mgr_get_device_by_devicecode(pDeviceCode,&node);
if (res != SUCCESS_RETURN) {
continue;
}
if(kk_subDev_check_scene_support(node->fatherDeviceCode) == 1){
gw_support_scene = 1;
}
else{
gw_support_scene = 0;
}
if(!strcmp(typeArray[k],"switch")){
for(idx = 0; idx < node->dev_shadow->property_number; idx++){
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
if(property == NULL){
continue;
}
if(strstr(property->identifier,"PowerSwitch") != NULL){
if(gw_support_scene){
kk_scene_action_detail_t info = {0};
memcpy(info.deviceCode,node->deviceCode,strlen(node->deviceCode));
memcpy(info.propertyName,property->identifier,strlen(property->identifier));
memcpy(info.propertyValue,propertyValue,strlen(propertyValue));
info.epNum = 1;
info.delay = 0;
kk_scene_action_add(node->fatherDeviceCode,sceneId,info);
}
res = kk_scene_insert_scene_action(type,node->deviceCode,1,
property->identifier,propertyValue,0,sceneId,node->fatherDeviceCode);
if(res != SUCCESS_RETURN){
INFO_PRINT("kk_subDev_set_action_by_productType fail!!!\n");
//return res;
continue;
}
}
res = kk_scene_insert_scene_action(type,node->deviceCode,1,
property->identifier,propertyValue,0,sceneId,node->fatherDeviceCode);
if(res != SUCCESS_RETURN){
INFO_PRINT("kk_subDev_set_action_by_productType fail!!!\n");
//return res;
continue;
}
}
}
}
else{
if(gw_support_scene){
kk_scene_action_detail_t info = {0};
memcpy(info.deviceCode,node->deviceCode,strlen(node->deviceCode));
memcpy(info.propertyName,propertyName,strlen(propertyName));
memcpy(info.propertyValue,propertyValue,strlen(propertyValue));
info.epNum = 1;
info.delay = 0;
kk_scene_action_add(node->fatherDeviceCode,sceneId,info);
}
res = kk_scene_insert_scene_action(type,node->deviceCode,1,
propertyName,propertyValue,0,sceneId,node->fatherDeviceCode);
if(res != SUCCESS_RETURN){
INFO_PRINT("kk_subDev_set_action_by_productType fail!!!\n");
//return res;
continue;
}
}
}
sqlite3_finalize(stmt);
sqlite3_free(sqlCmd);
else{
if(gw_support_scene){
kk_scene_action_detail_t info = {0};
memcpy(info.deviceCode,node->deviceCode,strlen(node->deviceCode));
memcpy(info.propertyName,propertyName,strlen(propertyName));
memcpy(info.propertyValue,propertyValue,strlen(propertyValue));
info.epNum = 1;
info.delay = 0;
kk_scene_action_add(node->fatherDeviceCode,sceneId,info);
}
res = kk_scene_insert_scene_action(type,node->deviceCode,1,
propertyName,propertyValue,0,sceneId,node->fatherDeviceCode);
if(res != SUCCESS_RETURN){
INFO_PRINT("kk_subDev_set_action_by_productType fail!!!\n");
//return res;
continue;
}
}
}
sqlite3_finalize(stmt);
sqlite3_free(sqlCmd);
}
return SUCCESS_RETURN;
}
......
......@@ -22,7 +22,7 @@
全局变量定义
*************************************************************/
extern sqlite3 *g_kk_pDb;
#define KK_HISTORY_MAX_COUNT 200
#define KK_HISTORY_MAX_COUNT 100
/*************************************************************
函数实现
*************************************************************/
......@@ -138,6 +138,36 @@ int kk_history_delete_by_recordtime(const char *table,time_t time)
return SUCCESS_RETURN;
}
/*查找数据个数*/
int sqlite_find_count(void)
{
kk_history_ctx_t *ctx = _kk_history_get_ctx();
char *sql = "select count(recordtime) from SensorHistoryInfo;";
sqlite3_stmt *stmt = NULL;
/*将sql语句转换为sqlite3可识别的语句,返回指针到stmt*/
int res = sqlite3_prepare_v2(ctx->pDb, sql, strlen(sql), &stmt, NULL);
if (SQLITE_OK != res || NULL == stmt) {
goto err1;
}
/*执行准备好的sqlite3语句*/
res = sqlite3_step(stmt);
if (res != SQLITE_ROW) {
goto err2;
}
int count = sqlite3_column_int(stmt, 0);
if (count < 0) {
goto err2;
}
INFO_PRINT("count = %d\n", count);
sqlite3_finalize(stmt);
return count;
err2:
sqlite3_finalize(stmt);
err1:
return -1;
}
/************************************************************
*功能描述: 插入传感器警告类信息到数据库
*输入参数: deviceCode:设备deviceCode
......@@ -156,6 +186,7 @@ int kk_history_insert_sensor_info(const char* deviceCode,const char* identifier,
char *zErrMsg = 0;
sqlite3_stmt *stmt;
time_t rtime = 0;
int count = 0;
const char *insertCmd = "insert into SensorHistoryInfo (deviceCode, identifier,value,recordtime) \
values ('%s','%s','%s','%d');";
......@@ -172,18 +203,21 @@ int kk_history_insert_sensor_info(const char* deviceCode,const char* identifier,
return FAIL_RETURN;
}
sqlite3_free(sqlCmd);
/*按时间删除超过最大数量的记录*/
const char *selectCmd = "select * from SensorHistoryInfo order by recordtime desc limit (select count(recordtime) from SensorHistoryInfo) offset %d";
sqlCmd = sqlite3_mprintf(selectCmd,KK_HISTORY_MAX_COUNT);
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
rtime = sqlite3_column_int(stmt, DB_SENSOR_RECORDTIME);
kk_history_delete_by_recordtime("SensorHistoryInfo",rtime);
}
sqlite3_finalize(stmt);
sqlite3_free(sqlCmd);
count = sqlite_find_count();
if(count > KK_HISTORY_MAX_COUNT)
{
/*按时间删除超过最大数量的记录*/
const char *selectCmd = "select * from SensorHistoryInfo order by recordtime desc";
sqlite3_prepare_v2(ctx->pDb, selectCmd, strlen(selectCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
rtime = sqlite3_column_int(stmt, DB_SENSOR_RECORDTIME);
kk_history_delete_by_recordtime("SensorHistoryInfo",rtime);
INFO_PRINT("delete rtime:%d\n",rtime);
break;
}
sqlite3_finalize(stmt);
}
_kk_history_unlock();
return SUCCESS_RETURN;
}
......@@ -208,6 +242,7 @@ int kk_history_insert_Outlet_info(const char* deviceCode,const char* power,const
char *zErrMsg = 0;
sqlite3_stmt *stmt;
time_t rtime = 0;
int count = 0;
const char *insertCmd = "insert into OutletHistoryInfo (deviceCode, power,metering,recordtime) \
values ('%s','%s','%s','%d');";
......@@ -224,18 +259,19 @@ int kk_history_insert_Outlet_info(const char* deviceCode,const char* power,const
return FAIL_RETURN;
}
sqlite3_free(sqlCmd);
/*按时间删除超过最大数量的记录*/
const char *selectCmd = "select * from OutletHistoryInfo order by recordtime desc limit (select count(recordtime) from OutletHistoryInfo) offset %d";
sqlCmd = sqlite3_mprintf(selectCmd,KK_HISTORY_MAX_COUNT);
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
rtime = sqlite3_column_int(stmt, DB_OUTLET_RECORDTIME);
kk_history_delete_by_recordtime("OutletHistoryInfo",rtime);
}
sqlite3_finalize(stmt);
sqlite3_free(sqlCmd);
count = sqlite_find_count();
if(count > KK_HISTORY_MAX_COUNT){
/*按时间删除超过最大数量的记录*/
//const char *selectCmd = "select * from OutletHistoryInfo order by recordtime desc limit (select count(recordtime) from OutletHistoryInfo) offset %d";
const char *selectCmd = "select * from OutletHistoryInfo order by recordtime desc";
sqlite3_prepare_v2(ctx->pDb, selectCmd, strlen(selectCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
rtime = sqlite3_column_int(stmt, DB_OUTLET_RECORDTIME);
kk_history_delete_by_recordtime("OutletHistoryInfo",rtime);
break;
}
sqlite3_finalize(stmt);
}
_kk_history_unlock();
return SUCCESS_RETURN;
}
......
......@@ -428,7 +428,6 @@ void kk_platMsg_handle(void* data, char* chalMark){
ERROR_PRINT("info or payload params error\n");
goto error;
}
msgType = cJSON_GetObjectItem(info, MSG_TYPE_STR);
info_dcode = cJSON_GetObjectItem(info, MSG_DEVICE_CODE_STR);
if (msgType == NULL || info_dcode == NULL){
......@@ -489,7 +488,10 @@ void kk_platMsg_handle(void* data, char* chalMark){
if(jsonPay == NULL) goto error;
char* outstr = cJSON_Print(payload);
dm_mgr_dev_node_t *search_node = NULL;
dm_mgr_get_device_by_devicecode(info_dcode->valuestring,&search_node);
res = dm_mgr_get_device_by_devicecode(info_dcode->valuestring,&search_node);
if (res < SUCCESS_RETURN) {
goto error;
}
if(search_node->isOffline){
/*如果是离线状态,上报在线给云端*/
dm_mgr_set_dev_onoffline(search_node,0);
......@@ -606,7 +608,7 @@ void kk_platMsg_handle(void* data, char* chalMark){
kk_history_insert_sensor_info(info_dcode->valuestring,eventItem->identifier,valueBuf,HAL_GetTime());
}
INFO_PRINT("kk_platMsg_handle data: event post\n");
dm_msg_thing_event_post(info_dcode->valuestring,eventItem->identifier);
dm_msg_thing_event_post(info_dcode->valuestring,eventItem->identifier,NULL);
kk_scene_iftt_check(info_dcode->valuestring,jsonPay);
}
......@@ -622,7 +624,7 @@ void kk_platMsg_handle(void* data, char* chalMark){
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);
dm_msg_thing_event_post(info_dcode->valuestring,eventItem->identifier,NULL);
}
}
......
......@@ -662,18 +662,50 @@ static int kk_scene_parse_repeatday(cJSON *repeatday)
if(repeatday == NULL){
return INVALID_PARAMETER;
}
int array_size = cJSON_GetArraySize (repeatday);
INFO_PRINT("array_size:%d\n",array_size);
if(array_size == 0){
weekflag = 0;
}else{
for(iCnt = 0; iCnt < array_size; iCnt++){
cJSON * pSub = cJSON_GetArrayItem(repeatday, iCnt);
if(pSub != NULL){
weekflag = weekflag|(1<<(pSub->valueint-1));
if(repeatday->type == cJSON_Array){
int array_size = cJSON_GetArraySize (repeatday);
INFO_PRINT("array_size:%d\n",array_size);
if(array_size == 0){
weekflag = 0;
}else{
for(iCnt = 0; iCnt < array_size; iCnt++){
cJSON * pSub = cJSON_GetArrayItem(repeatday, iCnt);
if(pSub != NULL){
weekflag = weekflag|(1<<(pSub->valueint-1));
}
}
}
}
else if(repeatday->type == cJSON_String){
if(strlen(repeatday->valuestring) == 0){
weekflag = 0;
}
else{
if(strstr(repeatday->valuestring,",") == NULL){
weekflag = 1<<(atoi(repeatday->valuestring)-1);
}
else{
char *tmp = repeatday->valuestring;
char *ptmp = NULL;
char weekStr[4] = {0};
while(1){
memset(weekStr,0x0,sizeof(weekStr));
ptmp = strstr(tmp,",");
if(ptmp != NULL){
strncpy(weekStr,tmp,ptmp-tmp);
weekflag = weekflag|(1<<(atoi(weekStr)-1));
}
else{
strncpy(weekStr,tmp,1);
weekflag = weekflag|(1<<(atoi(weekStr)-1));
break;
}
tmp = ptmp + 1;
}
}
}
}
INFO_PRINT("kk_scene_parse_repeatday weekflag:%d!!!\n",weekflag);
return weekflag;
......
......@@ -7,7 +7,7 @@
"cluster":"0x0500",
"attribute":"0x0002",
"iasStatusMask":"0x0001",
"reportFunc":"kk_tsl_report_iasZoneStatus",
"reportFunc":"",
"controlFunc":""
},{
"identity":"Battery",
......@@ -17,14 +17,6 @@
"iasStatusMask":"0x0008",
"reportFunc":"kk_tsl_report_battery",
"controlFunc":""
},{
"identity":"motionAlarm",
"endpoint":1,
"cluster":"0x0500",
"attribute":"0x0002",
"iasStatusMask":"0x0001",
"reportFunc":"",
"controlFunc":""
},{
"identity":"BatteryAlarm",
"endpoint":1,
......
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