Commit 4b4226d7 authored by chen.weican's avatar chen.weican

【修改内容】调整房间和楼层相关功能

【提交人】陈伟灿
parent ca07461a
This diff is collapsed.
......@@ -7,6 +7,11 @@ typedef struct kk_dev_list{
struct kk_dev_list * next;
}kk_dev_list_t;
typedef struct kk_floor_list{
char *floorId;
char *floorName;
struct kk_floor_list * next;
}kk_floor_list_t;
enum{
DB_ROOM_IDX = 0,
DB_ROOM_NAME,
......@@ -24,6 +29,11 @@ enum{
DB_DEV_EPNUM,
DB_DEV_DEV_NAME,
};
enum{
DB_FLOOR_IDX = 0,
DB_FLOOR_NAME,
DB_FLOOR_ID,
};
int kk_room_delete(const char *roomId);
int kk_room_add(const char *name,const char *roomId);
int kk_area_init(void);
......@@ -40,5 +50,8 @@ int kk_get_device_roomInfo(const char* deviceCode,int epNum,char *roomName,char
int kk_room_reset_armingstate(void);
int kk_room_dev_remove_by_roomid(const char *roomid);
int kk_room_set_floor_info(const char*floorId,const char* floorName,const char *roomid);
int kk_floor_delete_all(void);
int kk_floor_delete_by_id(char *floorId);
int kk_set_floor_to_default(const char*floorId);
#endif
......@@ -1684,6 +1684,9 @@ int dm_mgr_subdev_delete(_IN_ char deviceCode[DEVICE_CODE_MAXLEN])
if(strcmp(node->productType,KK_DM_AIR_GATEWAY_TYPE) == 0){
kk_indoorAir_delete_by_dcode(deviceCode);
}
if(strcmp(node->productType,KK_DM_AIR_SWITCH_GATEWAY_TYPE) == 0){
kk_subAirSwitch_delete_by_dcode(deviceCode);
}
if(node->dev_type == KK_DM_DEVICE_CCU){
ERROR_PRINT("ERROR [%s][%d]\n",__FUNCTION__,__LINE__);
return FAIL_RETURN;
......
......@@ -16,6 +16,7 @@
#define KK_DM_GW_DEVICE_PRODUCT_TYPE "gw"
#define KK_DM_GW_DEVICE_PRODUCT_CODE "2"
#define KK_DM_AIR_GATEWAY_TYPE "air conditioning gateway"
#define KK_DM_AIR_SWITCH_GATEWAY_TYPE "airswitch gateway"
#define KK_DM_DEVICE_CCU_DEVICEID (0x00)
#define MSG_MAX_LEN (64)
......
......@@ -97,14 +97,14 @@ const char DM_MSG_INFO[] DM_READ_ONLY;
#define KK_THING_SERVICE_SYNCDEVICEINFO_REPLY "/thing/service/syncDeviceInfo_reply"
#define KK_THING_SERVICE_CLOUDSTATUS "/thing/service/cloudStatus"
#define KK_THING_SERVICE_EXECUTEDNDMODE "/thing/service/executeDNDMode"
#define KK_THING_SERVICE_SETFLOOR "/thing/service/setAllFloors"
#define KK_THING_SERVICE_SETFLOOR_REPLY "/thing/service/setAllFloors_reply"
#define KK_THING_SERVICE_SETFLOOR "/thing/service/setRoomsToFloors"
#define KK_THING_SERVICE_SETFLOOR_REPLY "/thing/service/setRoomsToFloors_reply"
#define KK_THING_SERVICE_GETFLOOR "/thing/service/getAllFloors"
#define KK_THING_SERVICE_GETFLOOR_REPLY "/thing/service/getAllFloors_reply"
#define KK_THING_SERVICE_SYNCINFO_REPLY "/thing/service/syncinfo_reply"
#define KK_THING_SERVICE_SYNCINFOPUSH_REPLY "/thing/service/syncinfopush_reply"
#define KK_THING_SERVICE_ADDFLOORS "/thing/service/addFloors"
#define KK_THING_SERVICE_ADDFLOORS_REPLY "/thing/service/addFloors_reply"
#define KK_THING_EVENT_MESSAGE "/thing/event/"
#define KK_THING_SERVICE_GETGUARDSENSORS "/thing/service/getGuardSensors"
#define KK_THING_EVENT_POST "/post"
......@@ -116,6 +116,8 @@ const char DM_MSG_INFO[] DM_READ_ONLY;
#define KK_THING_SERVICE_HISTORYALARM_REPLY "/thing/service/historyAlarm_reply"
#define KK_THING_SERVICE_DEL_HISTORYALARM "/thing/service/delAlarm"
#define KK_THING_SERVICE_DEL_HISTORYALARM_REPLY "/thing/service/delAlarm_reply"
#define KK_THING_SERVICE_DELETEFLOORS "/thing/service/deleteFloors"
#define KK_THING_SERVICE_DELETEFLOORS_REPLY "/thing/service/deleteFloors_reply"
void kk_sendData2app(void *info, void *payload,int isAsync);
int dm_msg_thing_sub_register(_IN_ char productCode[DEVICE_CODE_MAXLEN], _IN_ char deviceCode[DEVICE_CODE_MAXLEN],
......
This diff is collapsed.
......@@ -115,6 +115,22 @@ static int _kk_property_db_Init(void)
_kk_property_db_unlock();
return FAIL_RETURN;
}
const char *pSubAirSwitchtable = "CREATE TABLE IF NOT EXISTS subAirSwitchProperties( \
idx INTEGER PRIMARY KEY, \
deviceCode varchar(33), \
identifier varchar(33), \
value varchar(33), \
valueType INTEGER, \
epNum INTEGER)";
if (sqlite3_exec(ctx->pDb, pSubAirSwitchtable, NULL, NULL, &pcErr) != SQLITE_OK)
{
ERROR_PRINT("Error creating table (%s)\n", pcErr);
sqlite3_free(pcErr);
//eUtils_LockUnlock(&sLock);
_kk_property_db_unlock();
return FAIL_RETURN;
}
//eUtils_LockUnlock(&sLock);
_kk_property_db_unlock();
return SUCCESS_RETURN;
......@@ -330,6 +346,164 @@ static int _kk_check_indoorAir_exist(const char* deviceCode,const char *identifi
_kk_property_db_unlock();
return isExist;
}
static int _kk_check_subAirSwitch_exist(const char* deviceCode,const char *identifier,int epNum)
{
int isExist = 0;
sqlite3_stmt *stmt;
char *pDeviceCode = NULL;
char *pIdentifier = NULL;
int epNumDb = 0;
kk_property_db_ctx_t *ctx = _kk_property_db_get_ctx();
const char *searchCmd = "select * from subAirSwitchProperties;";
_kk_property_db_lock();
sqlite3_prepare_v2(ctx->pDb, searchCmd, strlen(searchCmd), &stmt, NULL);
//INFO_PRINT("total_column = %d\n", sqlite3_column_count(stmt));
while(sqlite3_step(stmt) == SQLITE_ROW){
pDeviceCode = (char*)sqlite3_column_text(stmt, DB_INDOORAIR_DEVICECODE);
pIdentifier = (char*)sqlite3_column_text(stmt, DB_INDOORAIR_IDENTIFITER);
epNumDb = sqlite3_column_int(stmt, DB_INDOORAIR_EPNUM);
if((strcmp(deviceCode,pDeviceCode) == 0) && (strcmp(identifier,pIdentifier) == 0)&& (epNumDb == epNum))
{
isExist = 1;
break;
}
}
//INFO_PRINT("\n");
sqlite3_finalize(stmt);
_kk_property_db_unlock();
return isExist;
}
/************************************************************
*功能描述: 插入空开子设备属性到数据库
*输入参数: deviceCode:设备deviceCode
epNum:端点
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:属性的值插入的时候先置空,后续再update
*************************************************************/
int kk_subAirSwitch_db_insert(const char *deviceCode,const char *identifier,kk_tsl_data_type_e valuetype,int epNum)
{
const char *insertCmd = "insert into subAirSwitchProperties (deviceCode,identifier,value,valueType,epNum) \
values ('%s','%s','%s','%d','%d');";
char *sqlCmd = NULL;
int rc = 0;
char *zErrMsg = 0;
kk_property_db_ctx_t *ctx = _kk_property_db_get_ctx();
if(_kk_check_subAirSwitch_exist(deviceCode,identifier,epNum) == 1){
return SUCCESS_RETURN;
}
_kk_property_db_lock();
sqlCmd = sqlite3_mprintf(insertCmd,deviceCode,identifier,"",valuetype,epNum);
rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( rc != SQLITE_OK ){
ERROR_PRINT("SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
//INFO_PRINT("sub device insert data successfully\n");
}
sqlite3_free(sqlCmd);
_kk_property_db_unlock();
return SUCCESS_RETURN;
}
/************************************************************
*功能描述: 查询空开子设备数量
*输入参数: deviceCode:设备deviceCode
epList:端点列表
*输出参数: 子设备个数
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int kk_subAirSwitch_query_epnums(const char *deviceCode,int epList[])
{
char *sqlCmd = NULL;
//int rc = 0;
//char *zErrMsg = 0;
sqlite3_stmt *stmt;
char *valueStr = NULL;
int count = 0;
kk_property_db_ctx_t *ctx = _kk_property_db_get_ctx();
_kk_property_db_lock();
sqlCmd = sqlite3_mprintf("select * from subAirSwitchProperties WHERE deviceCode= '%s' and identifier = '%s'",deviceCode,"PowerSwitch");
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
if(count > 32){
return count;
}
epList[count] = sqlite3_column_int(stmt, DB_SUBAIRSWITCH_EPNUM);
printf("epList[count] :%d\n",epList[count]);
count++;
}
sqlite3_free(sqlCmd);
_kk_property_db_unlock();
sqlite3_finalize(stmt);
return count;
}
/************************************************************
*功能描述:通过deviceCode删除空开子设备
*输入参数: deviceCode:设备deviceCode
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int kk_subAirSwitch_delete_by_dcode(char deviceCode[DEVICE_CODE_MAXLEN])
{
const char *deleteCmd = "delete from subAirSwitchProperties where deviceCode = '%s';";
char *sqlCmd = NULL;
int rc = 0;
char *zErrMsg = 0;
kk_property_db_ctx_t *ctx = _kk_property_db_get_ctx();
_kk_property_db_lock();
sqlCmd = sqlite3_mprintf(deleteCmd,deviceCode);
INFO_PRINT("Table delete data sqlCmd:%s\n",sqlCmd);
rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( rc != SQLITE_OK ){
ERROR_PRINT("SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
INFO_PRINT("Table delete data successfully\n");
}
sqlite3_free(sqlCmd);
_kk_property_db_unlock();
return SUCCESS_RETURN;
}
/************************************************************
*功能描述: 更新属性值
*输入参数: deviceCode:设备deviceCode
identifier:属性名称
value:属性值
*输出参数: 无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int kk_subAirSwitch_db_update_value(const char *deviceCode,const char *identifier,const char* value,int epNum)
{
char *sqlCmd = NULL;
int rc = 0;
char *zErrMsg = 0;
kk_property_db_ctx_t *ctx = _kk_property_db_get_ctx();
_kk_property_db_lock();
//if()
sqlCmd = sqlite3_mprintf("UPDATE subAirSwitchProperties SET value='%s' WHERE (deviceCode= '%s' and epNum = '%d') and (identifier = '%s') ",value,deviceCode,epNum,identifier);
//DEBUG_PRINT("kk_property_db_update_value sqlCmd:%s\n",sqlCmd);
rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( rc != SQLITE_OK ){
ERROR_PRINT("SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
//DEBUG_PRINT("kk_property_db_update_value successfully\n");
}
sqlite3_free(sqlCmd);
_kk_property_db_unlock();
return SUCCESS_RETURN;
}
/************************************************************
*功能描述: 插入空调内机属性到数据库
*输入参数: deviceCode:设备deviceCode
......
......@@ -40,6 +40,14 @@ enum{
DB_INDOORAIR_VALUETYPE,
DB_INDOORAIR_EPNUM
};
enum{
DB_SUBAIRSWITCH_IDX = 0,
DB_SUBAIRSWITCH_DEVICECODE,
DB_SUBAIRSWITCH_IDENTIFITER,
DB_SUBAIRSWITCH_VALUE,
DB_SUBAIRSWITCH_VALUETYPE,
DB_SUBAIRSWITCH_EPNUM
};
int kk_property_db_init(void);
int kk_property_db_get_rawdata(const char *identifier,const int dev_type, kk_prop_raw_struct_t* raw, int count);
int kk_property_db_update_value(const char *deviceCode,const char *identifier,const char* value);
......@@ -57,5 +65,9 @@ int kk_indoorAir_db_update_value(const char *deviceCode,const char *identifier,c
int kk_indoorAir_query_epnums(const char *deviceCode,int epList[]);
int kk_check_property_exist(const char* deviceCode,const char* identifier);
int kk_indoorAir_delete_by_dcode(char deviceCode[DEVICE_CODE_MAXLEN]);
int kk_subAirSwitch_db_update_value(const char *deviceCode,const char *identifier,const char* value,int epNum);
int kk_subAirSwitch_delete_by_dcode(char deviceCode[DEVICE_CODE_MAXLEN]);
int kk_subAirSwitch_query_epnums(const char *deviceCode,int epList[]);
int kk_subAirSwitch_db_insert(const char *deviceCode,const char *identifier,kk_tsl_data_type_e valuetype,int epNum);
#endif
......@@ -654,7 +654,7 @@ static int kk_alarm_notify_handle(dm_mgr_dev_node_t *node,char *identifier,char
cJSON_Delete(info);
return 0;
}
static int kk_indoorAir_property_save(cJSON *payload,char *deviceCode)
static int kk_subDevice_property_save(cJSON *payload,char *deviceCode,int type)
{
dm_mgr_dev_node_t *node = NULL;
kk_tsl_data_t *property = NULL;
......@@ -698,13 +698,27 @@ static int kk_indoorAir_property_save(cJSON *payload,char *deviceCode)
char valBuf[16] = {0};
int value = propertyItem->valueint;
sprintf(valBuf,"%d",value);
kk_indoorAir_db_update_value(deviceCode,property->identifier,valBuf,epNumInt);
if(type == 0){
kk_indoorAir_db_update_value(deviceCode,property->identifier,valBuf,epNumInt);
}else if(type == 1){
kk_subAirSwitch_db_update_value(deviceCode,property->identifier,valBuf,epNumInt);
}
}else if(property->data_value.type == KK_TSL_DATA_TYPE_FLOAT || property->data_value.type == KK_TSL_DATA_TYPE_DOUBLE){
char valBuf[16] = {0};
sprintf(valBuf,"%f",propertyItem->valuedouble);
kk_indoorAir_db_update_value(deviceCode,property->identifier,valBuf,epNumInt);
if(type == 0){
kk_indoorAir_db_update_value(deviceCode,property->identifier,valBuf,epNumInt);
}else if(type == 1){
kk_subAirSwitch_db_update_value(deviceCode,property->identifier,valBuf,epNumInt);
}
}else if(property->data_value.type == KK_TSL_DATA_TYPE_TEXT ){
kk_indoorAir_db_update_value(deviceCode,property->identifier,propertyItem->valuestring,epNumInt);
if(type == 0){
kk_indoorAir_db_update_value(deviceCode,property->identifier,propertyItem->valuestring,epNumInt);
}else if(type == 1){
kk_subAirSwitch_db_update_value(deviceCode,property->identifier,propertyItem->valuestring,epNumInt);
}
}
}
......@@ -713,9 +727,10 @@ static int kk_indoorAir_property_save(cJSON *payload,char *deviceCode)
}
return 0;
}
static int kk_indoorAir_property_handle(cJSON *info,cJSON *payload,char *deviceCode)
/*type : 0,air condition gw;1,air switch gw*/
static int kk_subDevice_property_handle(cJSON *info,cJSON *payload,char *deviceCode,int type)
{
kk_indoorAir_property_save(payload,deviceCode);
kk_subDevice_property_save(payload,deviceCode,type);
cJSON_AddStringToObject(payload, MSG_DEVICE_CODE_STR, deviceCode);
char *payload11=cJSON_Print(payload);
char *infff=cJSON_Print(info);
......@@ -752,6 +767,34 @@ static int kk_indoorAir_online_handle(dm_mgr_dev_node_t *node ,char *deviceCode,
}
return 0;
}
static int kk_subAirSwitch_online_handle(dm_mgr_dev_node_t *node ,char *deviceCode,int epNum)
{
int idx = 0;
int gwExist = 0;
char roomId[32] = {0};
char roomName[256] = {0};
char epNumStr[10] = {0};
kk_tsl_data_t *property = NULL;
if(node == NULL){
return -1;
}
for(idx = 0; idx < node->dev_shadow->property_number; idx++){
property = (kk_tsl_data_t *)(node->dev_shadow->properties + idx);
if(property == NULL){
continue;
}
kk_subAirSwitch_db_insert(deviceCode,property->identifier,property->data_value.type,epNum);
}
gwExist = kk_get_device_roomInfo(deviceCode,1,roomName,roomId);//获取网关房间信息
if(gwExist){
char name[128] = {0};
sprintf(name,"空开%d",epNum);
sprintf(epNumStr,"%d",epNum);
kk_room_dev_add(roomId,roomName,deviceCode,epNumStr,name);
}
return 0;
}
void kk_platMsg_handle(void* data, char* chalMark){
int res = 0;
cJSON *json;
......@@ -828,7 +871,11 @@ void kk_platMsg_handle(void* data, char* chalMark){
cJSON *epNumJson = cJSON_GetObjectItem(jsonPay, "epNum");
if(epNumJson == NULL) goto error;
kk_indoorAir_online_handle(search_node,devCode->valuestring,epNumJson->valueint);
}
}else if(strcmp(search_node->productType,KK_DM_AIR_SWITCH_GATEWAY_TYPE) == 0){
cJSON *epNumJson = cJSON_GetObjectItem(jsonPay, "epNum");
if(epNumJson == NULL) goto error;
kk_subAirSwitch_online_handle(search_node,devCode->valuestring,epNumJson->valueint);
}
}
else if (strstr(msgType->valuestring, KK_THING_TOPO_BATCH_ADD_MSG) != NULL){
kk_ipc_send(IPC_MID2APP,data,strlen(data));
......@@ -859,7 +906,9 @@ void kk_platMsg_handle(void* data, char* chalMark){
dm_mgr_set_dev_onoffline(search_node,0);
}
if(strcmp(search_node->productType ,KK_DM_AIR_GATEWAY_TYPE) == 0){
kk_indoorAir_property_handle(info,payload,info_dcode->valuestring);
kk_subDevice_property_handle(info,payload,info_dcode->valuestring,0);
}else if(strcmp(search_node->productType ,KK_DM_AIR_SWITCH_GATEWAY_TYPE) == 0){
kk_subDevice_property_handle(info,payload,info_dcode->valuestring,1);
}
else{
/*插座类设备保存功率历史记录*/
......
......@@ -1857,6 +1857,25 @@
}
]
},
{
"pid": "00803109",
"name": "Air Switch Gateway",
"type": "ZR",
"ota": true,
"b_pid": 3109,
"productType": "airSwitchGateway",
"eps": [
{
"zid": "0300",
"cluster": {
"client": "0003:0006",
"server": "0000:0003:0004:0005:0006:0201:0202:fcc0"
}
}
]
},
{
"pid": "00048612",
"name": "XC Scene Panel 6G",
......@@ -1933,6 +1952,25 @@
}
]
},
{
"pid": "00800000",
"name": "BL Fresh Air Gateway",
"type": "ZR",
"ota": true,
"b_pid": 3122,
"productType": "freshAirGateway",
"eps": [
{
"zid": "0300",
"cluster": {
"client": "0003:0006",
"server": "0000:0003:0004:0005:0006:0201:0202:fcc0"
}
}
]
},
{
"pid": "04022115",
"name": "XB SOS Button",
......
......@@ -270,84 +270,6 @@
}
}
]
},
{
"identifier": "post",
"name": "post",
"type": "info",
"required": true,
"desc": "属性上报",
"method": "thing.event.property.post",
"outputData": [
{
"identifier": "Temperature",
"name": "目标温度",
"dataType": {
"type": "double",
"specs": {
"min": "16",
"max": "30",
"unit": "°C",
"unitName": "摄氏度",
"step": "0.5"
}
}
},
{
"identifier": "CurrentTemperature",
"name": "当前温度",
"dataType": {
"type": "double",
"specs": {
"min": "-30",
"max": "50",
"unit": "°C",
"unitName": "摄氏度",
"step": "1"
}
}
},
{
"identifier": "PowerSwitch",
"name": "电源开关",
"dataType": {
"type": "bool",
"specs": {
"0": "关闭",
"1": "开启"
}
}
},
{
"identifier": "WindSpeed",
"name": "风速",
"dataType": {
"type": "enum",
"specs": {
"0": "自动",
"2": "低档",
"3": "中档",
"4": "高档",
"6": "未知"
}
}
},
{
"identifier": "WorkMode",
"name": "工作模式",
"dataType": {
"type": "enum",
"specs": {
"0": "自动",
"1": "制冷",
"2": "制热",
"3": "通风",
"4": "除湿",
"5": "未知"
}
}
}
]
}
]
}
\ No newline at end of file
This diff is collapsed.
1.1.4
\ No newline at end of file
1.1.5
\ No newline at end of file
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