Commit c9deec65 authored by 陈伟灿's avatar 陈伟灿

Merge branch 'cwc' into 'master'

【修改内容】修改topo change的处理

See merge request chenweican/k-sdk!115
parents 880044d8 3bf85b9e
......@@ -44,11 +44,13 @@ static int _setDevice_Code(_IN_ char *device_code,int len)
static void KK_Ccuid_init(void)
{
uint8_t ccuid[DEVICE_CODE_LEN] = {0};
uint8_t ccuidTmp[DEVICE_CODE_LEN] = {0};
int ccuid_len = 0;
HAL_Execel_cmd(GET_CCUID_CMD,(char *)ccuid,sizeof(ccuid),&ccuid_len);
printf("GET_CCUID_CMD:%s\n",ccuid);
if(ccuid_len > 0 && ccuid_len <= DEVICE_CODE_LEN){
_setDevice_Code(ccuid,ccuid_len-1);
sprintf(ccuidTmp,"CCU_%s",ccuid);
_setDevice_Code(ccuidTmp,strlen(ccuidTmp)-1);//减一是因为最后有一个换行
}else{
_setDevice_Code(KK_CCU_ID,strlen(KK_CCU_ID));
}
......@@ -99,7 +101,7 @@ int main(int argc, char* argv[])
/*set the callback to get the device date to cloud*/
KK_Ccuid_init();
kk_ipc_init(IPC_APP2MID,(ipc_cb*)KK_Data_FromDev,NULL,NULL);
//kk_info_report_start();
kk_info_report_start();
again:
rc = kk_start_ccu_register();
if(rc == 0){
......
......@@ -33,7 +33,7 @@ static int kk_findccu_ack(int sockfd,struct sockaddr_in *addr){
args = cJSON_CreateObject();
if(args){
cJSON_AddItemToObject(json, "arg", args);
cJSON_AddStringToObject(args, "zkid", ccuid);
cJSON_AddStringToObject(args, "zkid", &ccuid[4]);
cJSON_AddStringToObject(args, "zk", KK_CCU_NAME);
HAL_Get_IP(s_IP,NULL);
cJSON_AddStringToObject(args, "ip", s_IP);
......
......@@ -231,7 +231,7 @@ int kk_ccu_opcode_handle(cJSON *root)
}else{
WARNING_PRINT("[%s][%d]\n",__FUNCTION__,__LINE__);
}
return 0;
}
......
......@@ -53,15 +53,17 @@ static int _setDevice_Code(_IN_ char *device_code,int len)
extern int HAL_Execel_cmd(char * cmd,char * buf,int buf_len,int* ret_len);
static void kk_lan_ccuid_init(void)
{
uint8_t ccuid[DEVICE_CODE_LEN] = {0};
int ccuid_len = 0;
HAL_Execel_cmd(GET_CCUID_CMD,(char *)ccuid,sizeof(ccuid),&ccuid_len);
printf("GET_CCUID_CMD:%s\n",ccuid);
if(ccuid_len > 0 && ccuid_len <= DEVICE_CODE_LEN){
_setDevice_Code((char *)ccuid,ccuid_len-1);
}else{
_setDevice_Code(KK_CCU_ID,strlen(KK_CCU_ID));
}
uint8_t ccuid[DEVICE_CODE_LEN] = {0};
uint8_t ccuidTmp[DEVICE_CODE_LEN] = {0};
int ccuid_len = 0;
HAL_Execel_cmd(GET_CCUID_CMD,(char *)ccuid,sizeof(ccuid),&ccuid_len);
printf("GET_CCUID_CMD:%s\n",ccuid);
if(ccuid_len > 0 && ccuid_len <= DEVICE_CODE_LEN){
sprintf(ccuidTmp,"CCU_%s",ccuid);
_setDevice_Code(ccuidTmp,strlen(ccuidTmp)-1);
}else{
_setDevice_Code(KK_CCU_ID,strlen(KK_CCU_ID));
}
}
......
......@@ -312,11 +312,15 @@ int kk_get_cloud_recv_status(void){
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int kk_topo_delete_handle(cJSON *payload)
int kk_topo_delete_handle(cJSON *payload,cJSON *buf)
{
if(payload == NULL){
int res = 0;
dm_mgr_dev_node_t *node = NULL;
dm_mgr_dev_node_t *gwnode = NULL;
if(payload == NULL || buf == NULL){
return FAIL_RETURN;
}
cJSON *paramStr = cJSON_GetObjectItem(payload, MSG_PARAMS_STR);
cJSON *state = cJSON_GetObjectItem(paramStr, MSG_TOPO_CHANGE_TYPE_STR);
if(state != NULL && state->valueint == 1){
......@@ -327,13 +331,33 @@ int kk_topo_delete_handle(cJSON *payload)
cJSON * item = deviceArray->child;
while(item != NULL){
char *deviceCode = cJSON_GetObjectItem(item,MSG_DEVICE_CODE_STR)->valuestring;
res = dm_mgr_get_device_by_devicecode(deviceCode, &node);
if (res < SUCCESS_RETURN) {
ERROR_PRINT("dm_mgr_search_device_by_pkdn failed");
return res;
}
res = dm_mgr_get_device_by_devicecode(node->fatherDeviceCode, &gwnode);
if (res < SUCCESS_RETURN) {
ERROR_PRINT("dm_mgr_search_device_by_pkdn failed");
return res;
}
cJSON* rootData=cJSON_CreateObject();
cJSON *info = cJSON_CreateObject();
cJSON_AddStringToObject(info, MSG_TYPE_STR, "/thing/topo/change");
cJSON_AddStringToObject(info, MSG_DEVICE_CODE_STR, gwnode->deviceCode);
cJSON_AddStringToObject(info, MSG_PRODUCT_CODE_STR, gwnode->productCode);
cJSON_AddItemToObject(rootData,"info",info);
cJSON_AddItemToObject(rootData,"payload",payload);
char *pnewout=cJSON_Print(rootData);
kk_sendData2gw(pnewout, strlen(pnewout), node->fatherDeviceCode);//send to gw itself
free(pnewout);
cJSON_Delete(rootData);
dm_mgr_subdev_delete(deviceCode);
item = item->next;
}
}
return SUCCESS_RETURN;
}
......@@ -460,6 +484,7 @@ static int kk_service_addDeviceToRoom_handle(cJSON *params)
if(roomId == NULL){
return FAIL_RETURN;
}
kk_room_add(room_name->valuestring,roomId->valuestring);
cJSON *deviceCode = cJSON_GetObjectItem(params, MSG_DEVICE_CODE_STR);
if(deviceCode == NULL){
return FAIL_RETURN;
......@@ -1332,6 +1357,11 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
kk_service_del_historyalarm_reply(info_root,key->valuestring);
}
}
else if(strcmp(typeJson->valuestring,KK_THING_TOPO_CHANGE_MSG) == 0){
INFO_PRINT("TOPO CHANGE \n");
kk_topo_delete_handle(payload,info_root);
//kk_sendData2gw(data, strlen(data), deviceCode->valuestring);//send to gw itself
}
else{
INFO_PRINT("Error msgtype!!! \n");
......
......@@ -2,7 +2,7 @@
#define _KK_LINKKIT_H_
#include "kk_tsl_common.h"
int kk_mid_subdev_batch_add( char productCode[PRODUCT_CODE_MAXLEN], char deviceCode[DEVICE_CODE_MAXLEN],char mac[DEVICE_MAC_MAXLEN],char fatherDeviceCode[DEVICE_CODE_MAXLEN]);
int kk_topo_delete_handle(cJSON *payload);
int kk_topo_delete_handle(cJSON *payload,cJSON *buf);
int kk_get_cloudstatus(void);
int kk_get_cloud_recv_status(void);
int kk_init_dmproc(void);
......
......@@ -102,11 +102,13 @@ static int _setDevice_Code(_IN_ char *device_code,int len)
static void HAL_Ccuid_init(void)
{
uint8_t ccuid[DEVICE_CODE_LEN] = {0};
uint8_t ccuidTmp[DEVICE_CODE_LEN] = {0};
int ccuid_len = 0;
HAL_Execel_cmd(GET_CCUID_CMD,(char *)ccuid,sizeof(ccuid),&ccuid_len);
printf("GET_CCUID_CMD:%s\n",ccuid);
if(ccuid_len > 0 && ccuid_len <= DEVICE_CODE_LEN){
_setDevice_Code(ccuid,ccuid_len-1);
sprintf(ccuidTmp,"CCU_%s",ccuid);
_setDevice_Code(ccuidTmp,strlen(ccuidTmp)-1);
}else{
_setDevice_Code(KK_CCU_ID,strlen(KK_CCU_ID));
}
......@@ -441,7 +443,7 @@ void mid_cb(void* data, int len){
}else if(devType == KK_DM_DEVICE_GATEWAY){
/*手机端主动删除设备,需要删除数据库相关内容,再下发给网关*/
if (strcmp(type->valuestring, KK_THING_TOPO_CHANGE_MSG)==0){
kk_topo_delete_handle(payload);
//kk_topo_delete_handle(payload,data);
}
kk_sendData2gw(data, strlen(data), deviceCode->valuestring);//send to gw itself
}else if(devType == KK_DM_DEVICE_SUBDEV){
......
{
"schema": "https://iot-ap.ikonke.com/model/product_3062.json",
"productType": "air conditioning gateway",
"version": "1.0",
"profile": {
"heartbeat": "300",
"productCode": "3062",
"productName": "中央空调控制器proZ3S(格力)"
},
"services": [
{
"identifier": "set",
"name": "set",
"required": true,
"callType": "async",
"desc": "属性设置",
"method": "thing.service.property.set",
"inputData": [
{
"identifier": "Temperature",
"name": "目标温度",
"dataType": {
"type": "double",
"specs": {
"min": "16",
"max": "30",
"unit": "°C",
"unitName": "摄氏度",
"step": "1"
}
}
},
{
"identifier": "PowerSwitch",
"name": "电源开关",
"dataType": {
"type": "bool",
"specs": {
"0": "关闭",
"1": "开启"
}
}
},
{
"identifier": "WindSpeed",
"name": "风速",
"dataType": {
"type": "enum",
"specs": {
"2": "低档",
"3": "中档",
"4": "高档"
}
}
},
{
"identifier": "WorkMode",
"name": "工作模式",
"dataType": {
"type": "enum",
"specs": {
"0": "自动",
"1": "制冷",
"2": "制热",
"3": "通风",
"4": "除湿"
}
}
}
],
"outputData": []
},
{
"identifier": "get",
"name": "get",
"required": true,
"callType": "async",
"desc": "属性获取",
"method": "thing.service.property.get",
"inputData": [],
"outputData": []
}
],
"properties": [
{
"identifier": "PowerSwitch",
"name": "电源开关",
"accessMode": "rw",
"required": true,
"dataType": {
"type": "enum",
"specs": {
"0": "关闭",
"1": "开启"
}
}
},
{
"identifier": "Temperature",
"name": "目标温度",
"accessMode": "rw",
"required": true,
"dataType": {
"type": "double",
"specs": {
"min": "16",
"max": "30",
"unit": "°C",
"unitName": "摄氏度",
"step": "1"
}
}
},
{
"identifier": "CurrentTemperature",
"name": "当前温度",
"accessMode": "r",
"required": true,
"dataType": {
"type": "double",
"specs": {
"min": "-30",
"max": "50",
"unit": "°C",
"unitName": "摄氏度",
"step": "1"
}
}
},
{
"identifier": "WindSpeed",
"name": "风速",
"accessMode": "rw",
"required": true,
"dataType": {
"type": "enum",
"specs": {
"0": "自动",
"2": "低档",
"3": "中档",
"4": "高档",
"6": "未知"
}
}
},
{
"identifier": "WorkMode",
"name": "工作模式",
"accessMode": "rw",
"required": true,
"dataType": {
"type": "enum",
"specs": {
"0": "自动",
"1": "制冷",
"2": "制热",
"3": "通风",
"4": "除湿",
"5": "未知"
}
}
}
],
"events": [
{
"identifier": "post",
"name": "post",
"type": "info",
"required": true,
"desc": "属性上报",
"method": "thing.event.property.post",
"outputData": [
{
"identifier": "CombineDeviceFlag",
"name": "复合设备标识",
"dataType": {
"type": "int",
"specs": {
"value": 1
}
}
},
{
"identifier": "EpTotal",
"name": "内机数+1",
"dataType": {
"type": "int",
"specs": {
"desc": "内机+网关 的数量"
}
}
},
{
"identifier": "eps",
"name": "内机属性集",
"dataType": {
"type": "array",
"specs": {
"item": [
{
"identifier": "Temperature",
"name": "目标温度",
"dataType": {
"type": "double",
"specs": {
"min": "16",
"max": "30",
"unit": "°C",
"unitName": "摄氏度",
"step": "1"
}
}
},
{
"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": "未知"
}
}
}
]
}
}
}
]
},
{
"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": "1"
}
}
},
{
"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
{
"schema": "https://iot-ap.ikonke.com/model/product_3102.json",
"productType": "lightPanel",
"version": "1.0",
"profile": {
"heartbeat": "300",
"productCode": "3102",
"productName": "海顿系列.零火线调光面板(KONKE)"
},
"services": [
{
"outputData": [],
"identifier": "set",
"inputData": [
{
"identifier": "PowerSwitch",
"dataType": {
"specs": {
"0": "关闭",
"1": "打开"
},
"type": "bool"
},
"name": "电源开关"
},
{
"identifier": "Brightness",
"dataType": {
"type": "int",
"specs": {
"min": "1",
"max": "100",
"unit": "%",
"unitName": "百分比",
"step": "1"
}
},
"name": "亮度"
},
{
"identifier": "FadeTime",
"dataType": {
"type": "int",
"specs": {
"min": "0",
"max": "254",
"unit": "s",
"unitName": "秒",
"step": "1"
}
},
"name": "渐变时间"
},
{
"identifier": "LowBrightness",
"dataType": {
"type": "int",
"specs": {
"min": "10",
"max": "90",
"unit": "%",
"unitName": "百分比",
"step": "1"
}
},
"name": "最低亮度"
},
{
"identifier": "HighBrightness",
"dataType": {
"type": "int",
"specs": {
"min": "20",
"max": "100",
"unit": "%",
"unitName": "百分比",
"step": "1"
}
},
"name": "最高亮度"
}
],
"method": "thing.service.property.set",
"name": "set",
"required": true,
"callType": "async",
"desc": "属性设置"
},
{
"outputData": [
{
"identifier": "PowerSwitch",
"dataType": {
"specs": {
"0": "关闭",
"1": "打开"
},
"type": "bool"
},
"name": "电源开关"
},
{
"identifier": "Brightness",
"dataType": {
"type": "int",
"specs": {
"min": "1",
"max": "100",
"unit": "%",
"unitName": "百分比",
"step": "1"
}
},
"name": "亮度"
},
{
"identifier": "FadeTime",
"dataType": {
"type": "int",
"specs": {
"min": "0",
"max": "254",
"unit": "s",
"unitName": "秒",
"step": "1"
}
},
"name": "渐变时间"
},
{
"identifier": "LowBrightness",
"dataType": {
"type": "int",
"specs": {
"min": "10",
"max": "90",
"unit": "%",
"unitName": "百分比",
"step": "1"
}
},
"name": "最低亮度"
},
{
"identifier": "HighBrightness",
"dataType": {
"type": "int",
"specs": {
"min": "20",
"max": "100",
"unit": "%",
"unitName": "百分比",
"step": "1"
}
},
"name": "最高亮度"
}
],
"identifier": "get",
"inputData": [
"PowerSwitch",
"Brightness",
"FadeTime",
"LowBrightness",
"HighBrightness"
],
"method": "thing.service.property.get",
"name": "get",
"required": true,
"callType": "async",
"desc": "属性获取"
},
{
"outputData":[
],
"identifier":"negativeProperty",
"inputData":[
"PowerSwitch"
],
"method":"thing.service.negativeProperty",
"name":"negativeProperty",
"required":true,
"callType":"async",
"desc":"属性值取反"
}
],
"properties": [
{
"identifier": "PowerSwitch",
"dataType": {
"specs": {
"0": "关闭",
"1": "打开"
},
"type": "bool"
},
"name": "电源开关",
"accessMode": "rw",
"required": true
},
{
"identifier": "Brightness",
"name": "亮度",
"accessMode": "rw",
"required": false,
"dataType": {
"type": "int",
"specs": {
"min": "1",
"max": "100",
"unit": "%",
"unitName": "百分比",
"step": "1"
}
}
},
{
"identifier": "FadeTime",
"accessMode": "rw",
"required": false,
"dataType": {
"type": "int",
"specs": {
"min": "0",
"max": "254",
"unit": "s",
"unitName": "秒",
"step": "1"
}
},
"name": "渐变时间"
},
{
"identifier": "LowBrightness",
"accessMode": "rw",
"required": false,
"dataType": {
"type": "int",
"specs": {
"min": "10",
"max": "90",
"unit": "%",
"unitName": "百分比",
"step": "1"
}
},
"name": "最低亮度"
},
{
"identifier": "HighBrightness",
"accessMode": "rw",
"required": false,
"dataType": {
"type": "int",
"specs": {
"min": "20",
"max": "100",
"unit": "%",
"unitName": "百分比",
"step": "1"
}
},
"name": "最高亮度"
}
],
"events": [
{
"outputData": [
{
"identifier": "PowerSwitch",
"dataType": {
"specs": {
"0": "关闭",
"1": "打开"
},
"type": "bool"
},
"name": "电源开关"
},
{
"identifier": "Brightness",
"dataType": {
"type": "int",
"specs": {
"min": "1",
"max": "100",
"unit": "%",
"unitName": "百分比",
"step": "1"
}
},
"name": "亮度"
},
{
"identifier": "FadeTime",
"dataType": {
"type": "int",
"specs": {
"min": "0",
"max": "254",
"unit": "s",
"unitName": "秒",
"step": "1"
}
},
"name": "渐变时间"
},
{
"identifier": "LowBrightness",
"dataType": {
"type": "int",
"specs": {
"min": "10",
"max": "90",
"unit": "%",
"unitName": "百分比",
"step": "1"
}
},
"name": "最低亮度"
},
{
"identifier": "HighBrightness",
"dataType": {
"type": "int",
"specs": {
"min": "20",
"max": "100",
"unit": "%",
"unitName": "百分比",
"step": "1"
}
},
"name": "最高亮度"
}
],
"identifier": "property",
"method": "thing.event.property.post",
"name": "property",
"type": "info",
"required": true,
"desc": "属性上报"
}
]
}
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