Commit 8b94e9dc authored by 陈伟灿's avatar 陈伟灿

Merge branch 'cwc' into 'master'

【修改内容】增加门锁相关的service和event事件的处理

See merge request chenweican/k-sdk!43
parents 08f38ecd 57d46407
...@@ -61,6 +61,36 @@ typedef enum { ...@@ -61,6 +61,36 @@ typedef enum {
#define MSG_TIMER_SETCOUNTDOWN_GETCOUNTDOWN "getCountDown" #define MSG_TIMER_SETCOUNTDOWN_GETCOUNTDOWN "getCountDown"
#define MSG_PROPERTY_STR "property" #define MSG_PROPERTY_STR "property"
/************************LOCK KEY*************************/
#define MSG_KEYDELETE_NOTIFICATION_KEYID "KeyDeletedNotification.KeyID"
#define MSG_KEYDELETE_NOTIFICATION_KEYTYPE "KeyDeletedNotification.KeyType"
#define MSG_KEYDELETE_NOTIFICATION_KEYROLE "KeyDeletedNotification.KeyRole"
#define MSG_KEYADD_NOTIFICATION_KEYID "KeyAddNotification.KeyID"
#define MSG_KEYADD_NOTIFICATION_KEYTYPE "KeyAddNotification.KeyType"
#define MSG_KEYADD_NOTIFICATION_KEYROLE "KeyAddNotification.KeyRole"
#define MSG_KEYADD_NOTIFICATION_KEYISVALID "KeyAddNotification.IsValid"
#define MSG_KEYADD_NOTIFICATION_KEYNAME "KeyAddNotification.KeyName"
#define MSG_KEYADD_NOTIFICATION_KEYEFFECTIVE "KeyAddNotification.KeyEffectiveTime"
#define MSG_KEYADD_NOTIFICATION_KEYEXPIRE "KeyAddNotification.KeyExpiryTime"
#define MSG_KEYMODIFY_NOTIFICATION_KEYID "KeyModifyNotification.KeyID"
#define MSG_KEYMODIFY_NOTIFICATION_KEYTYPE "KeyModifyNotification.KeyType"
#define MSG_KEYMODIFY_NOTIFICATION_KEYROLE "KeyModifyNotification.KeyRole"
#define MSG_KEYMODIFY_NOTIFICATION_KEYISVALID "KeyModifyNotification.IsValid"
#define MSG_KEYMODIFY_NOTIFICATION_KEYNAME "KeyModifyNotification.KeyName"
#define MSG_KEYMODIFY_NOTIFICATION_KEYEFFECTIVE "KeyModifyNotification.KeyEffectiveTime"
#define MSG_KEYMODIFY_NOTIFICATION_KEYEXPIRE "KeyModifyNotification.KeyExpiryTime"
#define MSG_KEYADD_KEYID "KeyID"
#define MSG_KEYADD_KEYTYPE "KeyType"
#define MSG_KEYADD_KEYROLE "KeyRole"
#define MSG_KEYADD_KEYISVALID "IsValid"
#define MSG_KEYADD_KEYNAME "KeyName"
#define MSG_KEYADD_KEYEFFECTIVE "KeyEffectiveTime"
#define MSG_KEYADD_KEYEXPIRE "KeyExpiryTime"
#define MSG_KEYADD_NOTIFICATION "KeyAddNotification"
#define MSG_KEYDELETE_NOTIFICATION "KeyDeletedNotification"
#define MSG_KEYMODIFY_NOTIFICATION "KeyModifyNotification"
......
{
"schema":"https://iotx-tsl.oss-ap-southeast-1.aliyuncs.com/schema.json",
"productType":"gw",
"profile":{
"type":"KONKE_ZIGBEE_Gateway"
},
"properties":[
{
"identifier":"NetChannelState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"组网通道状态",
"accessMode":"rw",
"required":true
},
{
"identifier":"WhiteListState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"白名单状态",
"accessMode":"rw",
"required":false
},
{
"identifier":"OnlineDetectionState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"在线侦测开关状态",
"accessMode":"rw",
"required":false
},
{
"identifier":"SN",
"dataType":{
"specs":{
"length":"50"
},
"type":"text"
},
"name":"设备SN",
"accessMode":"r",
"required":false
},
{
"identifier":"IPAddress",
"dataType":{
"specs":{
"length":"255"
},
"type":"text"
},
"name":"IP地址",
"accessMode":"r",
"required":false
},
{
"identifier":"MACAddress",
"dataType":{
"specs":{
"length":"128"
},
"type":"text"
},
"name":"MAC地址",
"accessMode":"r",
"required":false
},
{
"identifier":"Port",
"dataType":{
"specs":{
"min":"0",
"max":"65535",
"step":"1"
},
"type":"int"
},
"name":"网关通信端口号",
"accessMode":"r",
"required":false
},
{
"identifier":"Version",
"dataType":{
"specs":{
"length":"255"
},
"type":"text"
},
"name":"版本",
"accessMode":"r",
"required":false
}],
"services":[
{
"outputData":[
],
"identifier":"set",
"inputData":[
{
"identifier":"NetChannelState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"组网通道状态"
},
{
"identifier":"WhiteListState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"白名单状态"
},
{
"identifier":"OnlineDetectionState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"在线侦测开关状态"
}],
"method":"thing.service.property.set",
"name":"set",
"required":true,
"callType":"async",
"desc":"属性设置"
},
{
"outputData":[
{
"identifier":"NetChannelState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"组网通道状态"
},
{
"identifier":"WhiteListState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"白名单状态"
},
{
"identifier":"OnlineDetectionState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"在线侦测开关状态"
},
{
"identifier":"SN",
"dataType":{
"specs":{
"length":"50"
},
"type":"text"
},
"name":"设备SN"
},
{
"identifier":"IPAddress",
"dataType":{
"specs":{
"length":"255"
},
"type":"text"
},
"name":"IP地址"
},
{
"identifier":"MACAddress",
"dataType":{
"specs":{
"length":"128"
},
"type":"text"
},
"name":"MAC地址"
},
{
"identifier":"Port",
"dataType":{
"specs":{
"min":"0",
"max":"65535",
"step":"1"
},
"type":"int"
},
"name":"网关通信端口号"
},
{
"identifier":"Version",
"dataType":{
"specs":{
"length":"255"
},
"type":"text"
},
"name":"版本",
"accessMode":"r"
}],
"identifier":"get",
"inputData":[
"NetChannelState",
"WhiteListState",
"OnlineDetectionState",
"SN",
"IPAddress",
"MACAddress",
"Port",
"Version"],
"method":"thing.service.property.get",
"name":"get",
"required":true,
"callType":"async",
"desc":"属性获取"
},
{
"outputData":[
],
"identifier":"restoreFactory",
"inputData":[
],
"method":"thing.service.restoreFactory",
"name":"restoreFactory",
"required":false,
"callType":"async",
"desc":"恢复出厂设置"
},
{
"outputData":[
],
"identifier":"addWhiteList",
"inputData":[
{
"identifier":"Devices",
"dataType":{
"specs":{
"item":{
"specs":[
{
"identifier":"MACAddress",
"dataType":{
"specs":{
"length":"128"
},
"type":"text"
},
"name":"MAC地址"
},
{
"identifier":"ProductId",
"dataType":{
"specs":{
"length":"2048"
},
"type":"text"
},
"name":"产品id"
}],
"type":"struct"
},
"size":"512"
},
"type":"array"
},
"name":"设备列表"
}],
"method":"thing.service.addWhiteList",
"name":"添加设备白名单",
"required":false,
"callType":"async"
},
{
"outputData":[
],
"identifier":"deleteWhiteList",
"inputData":[
{
"identifier":"Devices",
"dataType":{
"specs":{
"item":{
"specs":[
{
"identifier":"MACAddress",
"dataType":{
"specs":{
"length":"128"
},
"type":"text"
},
"name":"MAC地址"
}],
"type":"struct"
},
"size":"512"
},
"type":"array"
},
"name":"设备列表"
}],
"method":"thing.service.deleteWhiteList",
"name":"删除白名单",
"required":false,
"callType":"async"
},
{
"outputData":[
],
"inputData":[
],
"identifier":"getWhiteList",
"method":"thing.service.getWhiteList",
"name":"获取白名单列表",
"required":false,
"callType":"async"
}],
"events":[
{
"outputData":[
{
"identifier":"NetChannelState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"组网通道状态"
},
{
"identifier":"WhiteListState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"白名单状态"
},
{
"identifier":"OnlineDetectionState",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"在线侦测开关状态"
},
{
"identifier":"SN",
"dataType":{
"specs":{
"length":"50"
},
"type":"text"
},
"name":"设备SN"
},
{
"identifier":"IPAddress",
"dataType":{
"specs":{
"length":"255"
},
"type":"text"
},
"name":"IP地址"
},
{
"identifier":"MACAddress",
"dataType":{
"specs":{
"length":"128"
},
"type":"text"
},
"name":"MAC地址"
},
{
"identifier":"Port",
"dataType":{
"specs":{
"min":"0",
"max":"65535",
"step":"1"
},
"type":"int"
},
"name":"网关通信端口号"
}],
"identifier":"property",
"method":"thing.event.property.post",
"name":"property",
"type":"info",
"required":true,
"desc":"属性上报"
},
{
"outputData":[
],
"identifier":"whiteListAddedNotification",
"method":"thing.event.whiteListAddedNotification.post",
"name":"添加设备白名单通知",
"type":"info",
"required":false
},
{
"outputData":[
],
"identifier":"whiteListDeletedNotification",
"method":"thing.event.whiteListDeletedNotification.post",
"name":"删除设备白名单通知",
"type":"info",
"required":false
},
{
"outputData":[
{
"identifier":"Devices",
"dataType":{
"specs":{
"item":{
"specs":[
{
"identifier":"SN",
"dataType":{
"specs":{
"length":"50"
},
"type":"text"
},
"name":"设备sn"
},
{
"identifier":"deviceId",
"dataType":{
"specs":{
"length":"128"
},
"type":"text"
},
"name":"设备ID"
},
{
"identifier":"MACAddress",
"dataType":{
"specs":{
"length":"128"
},
"type":"text"
},
"name":"MAC地址"
},
{
"identifier":"ProductId",
"dataType":{
"specs":{
"length":"2048"
},
"type":"text"
},
"name":"产品id"
}],
"type":"struct"
},
"size":"512"
},
"type":"array"
},
"name":"设备列表"
}],
"identifier":"getWhiteListNotification",
"method":"thing.event.getWhiteList.post",
"name":"getWhiteList",
"type":"info",
"required":false,
"desc":"获取白名单通知消息"
},
{
"outputData":[
],
"identifier":"restoreFactoryNotification",
"method":"thing.event.restoreFactoryNotification.post",
"name":"恢复出厂通知消息",
"type":"info",
"required":false
},
{
"outputData":[
{
"identifier":"ErrorCode",
"dataType":{
"specs":{
"0":"正常"
},
"type":"enum"
},
"name":"故障代码"
}],
"identifier":"error",
"method":"thing.event.error.post",
"name":"故障上报",
"type":"error",
"required":false
}]
}
...@@ -65,11 +65,17 @@ const char DM_MSG_INFO[] DM_READ_ONLY; ...@@ -65,11 +65,17 @@ const char DM_MSG_INFO[] DM_READ_ONLY;
#define KK_THING_SERVICE_GETLOCALTIMER "/thing/service/getLocalTimer" #define KK_THING_SERVICE_GETLOCALTIMER "/thing/service/getLocalTimer"
#define KK_THING_SERVICE_SETCOUNTDOWN "/thing/service/setCountDown" #define KK_THING_SERVICE_SETCOUNTDOWN "/thing/service/setCountDown"
#define KK_THING_SERVICE_GETCOUNTDOWN "/thing/service/getCountDown" #define KK_THING_SERVICE_GETCOUNTDOWN "/thing/service/getCountDown"
#define KK_THING_SERVICE_GETKEYLIST "/thing/service/GetKeyList"
#define KK_THING_SERVICE_ADDKEY "/thing/service/AddKey"
#define KK_THING_SERVICE_DELETEKEY "/thing/service/DeleteKey"
#define KK_THING_SERVICE_MODIFYKEY "/thing/service/ModifyKey"
#define KK_THING_EVENT_MESSAGE "/thing/event/" #define KK_THING_EVENT_MESSAGE "/thing/event/"
#define KK_THING_EVENT_POST "/post" #define KK_THING_EVENT_POST "/post"
//const char DM_URI_SYS_PREFIX[] DM_READ_ONLY = "/sys/%s/%s/"; //const char DM_URI_SYS_PREFIX[] DM_READ_ONLY = "/sys/%s/%s/";
......
...@@ -479,7 +479,6 @@ static int kk_service_setCountDown_handle(cJSON *params,const char *deviceCode) ...@@ -479,7 +479,6 @@ static int kk_service_setCountDown_handle(cJSON *params,const char *deviceCode)
} }
cJSON * item = LocalTimerArray->child; cJSON * item = LocalTimerArray->child;
while(item != NULL){ while(item != NULL){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
delaytimer = cJSON_GetObjectItem(item,MSG_TIMER_SETCOUNTDOWN_DELAYTIME)->valueint; delaytimer = cJSON_GetObjectItem(item,MSG_TIMER_SETCOUNTDOWN_DELAYTIME)->valueint;
current = cJSON_GetObjectItem(item,MSG_TIMER_SETCOUNTDOWN_CURRENTTIME)->valueint; current = cJSON_GetObjectItem(item,MSG_TIMER_SETCOUNTDOWN_CURRENTTIME)->valueint;
isValid = cJSON_GetObjectItem(item,MSG_TIMER_SETLOCALTIMER_ISVALID)->valueint; isValid = cJSON_GetObjectItem(item,MSG_TIMER_SETLOCALTIMER_ISVALID)->valueint;
...@@ -501,6 +500,123 @@ static int kk_service_getCountDown_handle(const char *deviceCode) ...@@ -501,6 +500,123 @@ static int kk_service_getCountDown_handle(const char *deviceCode)
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
static int kk_service_getLockKeylist_handle(const char *deviceCode)
{
if(deviceCode == NULL){
return INVALID_PARAMETER;
}
return SUCCESS_RETURN;
}
static int kk_service_addKey_handle(const char *deviceCode,cJSON *param)
{
char keyId[32] = {0};
uint64_t u64KeyId = 0;
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if(deviceCode == NULL || param == NULL){
return INVALID_PARAMETER;
}
res = dm_mgr_get_device_by_devicecode(deviceCode, &node);
if (res < SUCCESS_RETURN) {
ERROR_PRINT("dm_mgr_get_device_by_devicecode failed\n");
return res;
}
cJSON *KeyType = cJSON_GetObjectItem(param,MSG_KEYADD_KEYTYPE);
if(KeyType == NULL) return FAIL_RETURN;
cJSON *KeyRole = cJSON_GetObjectItem(param,MSG_KEYADD_KEYROLE);
if(KeyRole == NULL) return FAIL_RETURN;
cJSON *IsValid = cJSON_GetObjectItem(param,MSG_KEYADD_KEYISVALID);
if(IsValid == NULL) return FAIL_RETURN;
cJSON *KeyName = cJSON_GetObjectItem(param,MSG_KEYADD_KEYNAME);
if(KeyName == NULL) return FAIL_RETURN;;
cJSON *KeyEffectiveTime = cJSON_GetObjectItem(param,MSG_KEYADD_KEYEFFECTIVE);
if(KeyEffectiveTime == NULL) return FAIL_RETURN;;
cJSON *KeyExpiryTime = cJSON_GetObjectItem(param,MSG_KEYADD_KEYEXPIRE);
if(KeyExpiryTime == NULL) return FAIL_RETURN;;
u64KeyId = get_unique_id();
sprintf(keyId,"%u",u64KeyId);
kk_property_update_lockkeys(deviceCode,keyId,KeyType->valueint,KeyRole->valueint,IsValid->valueint,
KeyName->valuestring,KeyEffectiveTime->valueint,KeyExpiryTime->valueint);
kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,MSG_KEYADD_NOTIFICATION_KEYID,NULL,keyId);
kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,MSG_KEYADD_NOTIFICATION_KEYTYPE,&KeyType->valueint,NULL);
kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,MSG_KEYADD_NOTIFICATION_KEYROLE,&KeyRole->valueint,NULL);
kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,MSG_KEYADD_NOTIFICATION_KEYISVALID,&IsValid->valueint,NULL);
kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,MSG_KEYADD_NOTIFICATION_KEYNAME,NULL,KeyName->valuestring);
kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,MSG_KEYADD_NOTIFICATION_KEYEFFECTIVE,&IsValid->valueint,NULL);
kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,MSG_KEYADD_NOTIFICATION_KEYEXPIRE,&IsValid->valueint,NULL);
return SUCCESS_RETURN;
}
static int kk_service_modifyKey_handle(const char *deviceCode,cJSON *param)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if(deviceCode == NULL || param == NULL){
return INVALID_PARAMETER;
}
res = dm_mgr_get_device_by_devicecode(deviceCode, &node);
if (res < SUCCESS_RETURN) {
ERROR_PRINT("dm_mgr_get_device_by_devicecode failed\n");
return res;
}
cJSON *keyId = cJSON_GetObjectItem(param,MSG_KEYADD_KEYID);
if(keyId == NULL) return FAIL_RETURN;
cJSON *KeyType = cJSON_GetObjectItem(param,MSG_KEYADD_KEYTYPE);
if(KeyType == NULL) return FAIL_RETURN;
cJSON *KeyRole = cJSON_GetObjectItem(param,MSG_KEYADD_KEYROLE);
if(KeyRole == NULL) return FAIL_RETURN;
cJSON *IsValid = cJSON_GetObjectItem(param,MSG_KEYADD_KEYISVALID);
if(IsValid == NULL) return FAIL_RETURN;
cJSON *KeyName = cJSON_GetObjectItem(param,MSG_KEYADD_KEYNAME);
if(KeyName == NULL) return FAIL_RETURN;;
cJSON *KeyEffectiveTime = cJSON_GetObjectItem(param,MSG_KEYADD_KEYEFFECTIVE);
if(KeyEffectiveTime == NULL) return FAIL_RETURN;;
cJSON *KeyExpiryTime = cJSON_GetObjectItem(param,MSG_KEYADD_KEYEXPIRE);
if(KeyExpiryTime == NULL) return FAIL_RETURN;;
kk_property_update_lockkeys(deviceCode,keyId->valuestring,KeyType->valueint,KeyRole->valueint,IsValid->valueint,
KeyName->valuestring,KeyEffectiveTime->valueint,KeyExpiryTime->valueint);
kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,MSG_KEYMODIFY_NOTIFICATION_KEYID,NULL,keyId->valuestring);
kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,MSG_KEYMODIFY_NOTIFICATION_KEYTYPE,&KeyType->valueint,NULL);
kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,MSG_KEYMODIFY_NOTIFICATION_KEYROLE,&KeyRole->valueint,NULL);
kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,MSG_KEYMODIFY_NOTIFICATION_KEYISVALID,&IsValid->valueint,NULL);
kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,MSG_KEYMODIFY_NOTIFICATION_KEYNAME,NULL,KeyName->valuestring);
kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,MSG_KEYMODIFY_NOTIFICATION_KEYEFFECTIVE,&IsValid->valueint,NULL);
kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,MSG_KEYMODIFY_NOTIFICATION_KEYEXPIRE,&IsValid->valueint,NULL);
return SUCCESS_RETURN;
}
static int kk_service_deleteKey_handle(const char *deviceCode,cJSON *param)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if(deviceCode == NULL || param == NULL){
return INVALID_PARAMETER;
}
res = dm_mgr_get_device_by_devicecode(deviceCode, &node);
if (res < SUCCESS_RETURN) {
ERROR_PRINT("dm_mgr_get_device_by_devicecode failed\n");
return res;
}
cJSON *KeyType = cJSON_GetObjectItem(param,MSG_KEYADD_KEYTYPE);
if(KeyType == NULL) return FAIL_RETURN;
cJSON *KeyRole = cJSON_GetObjectItem(param,MSG_KEYADD_KEYROLE);
if(KeyRole == NULL) return FAIL_RETURN;
cJSON *keyId = cJSON_GetObjectItem(param,MSG_KEYADD_KEYID);
if(keyId == NULL) return FAIL_RETURN;
kk_property_delete_lockkeys(deviceCode,keyId->valuestring);
kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,MSG_KEYDELETE_NOTIFICATION_KEYID,NULL,keyId->valuestring);
kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,MSG_KEYDELETE_NOTIFICATION_KEYTYPE,&KeyType->valueint,NULL);
kk_tsl_set_value(kk_tsl_set_event_output_value,node->dev_shadow,MSG_KEYDELETE_NOTIFICATION_KEYROLE,&KeyRole->valueint,NULL);
return SUCCESS_RETURN;
}
static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
{ {
...@@ -656,8 +772,33 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) ...@@ -656,8 +772,33 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
else if(strcmp(typeJson->valuestring,KK_THING_SERVICE_GETCOUNTDOWN) == 0){ else if(strcmp(typeJson->valuestring,KK_THING_SERVICE_GETCOUNTDOWN) == 0){
INFO_PRINT(" get count down \n"); INFO_PRINT(" get count down \n");
cJSON *deviceCode = cJSON_GetObjectItem(info_root, MSG_DEVICE_CODE_STR); cJSON *deviceCode = cJSON_GetObjectItem(info_root, MSG_DEVICE_CODE_STR);
printf("[%s][%d]deviceCode->valuestring:%s\n",__FUNCTION__,__LINE__,deviceCode->valuestring);
kk_service_getCountDown_handle(deviceCode->valuestring); kk_service_getCountDown_handle(deviceCode->valuestring);
}
else if(strcmp(typeJson->valuestring,KK_THING_SERVICE_GETKEYLIST) == 0){
INFO_PRINT(" get key list \n");
cJSON *deviceCode = cJSON_GetObjectItem(info_root, MSG_DEVICE_CODE_STR);
kk_service_getLockKeylist_handle(deviceCode->valuestring);
}
else if(strcmp(typeJson->valuestring,KK_THING_SERVICE_ADDKEY) == 0){
INFO_PRINT(" add key \n");
cJSON *deviceCode = cJSON_GetObjectItem(info_root, MSG_DEVICE_CODE_STR);
cJSON *paramStr = cJSON_GetObjectItem(payload, MSG_PARAMS_STR);
kk_service_addKey_handle(deviceCode->valuestring,paramStr);
dm_msg_thing_event_post(deviceCode->valuestring,MSG_KEYADD_NOTIFICATION);
}
else if(strcmp(typeJson->valuestring,KK_THING_SERVICE_MODIFYKEY) == 0){
INFO_PRINT(" modify key \n");
cJSON *deviceCode = cJSON_GetObjectItem(info_root, MSG_DEVICE_CODE_STR);
cJSON *paramStr = cJSON_GetObjectItem(payload, MSG_PARAMS_STR);
kk_service_modifyKey_handle(deviceCode->valuestring,paramStr);
dm_msg_thing_event_post(deviceCode->valuestring,MSG_KEYMODIFY_NOTIFICATION);
}
else if(strcmp(typeJson->valuestring,KK_THING_SERVICE_DELETEKEY) == 0){
INFO_PRINT(" delete key \n");
cJSON *deviceCode = cJSON_GetObjectItem(info_root, MSG_DEVICE_CODE_STR);
cJSON *paramStr = cJSON_GetObjectItem(payload, MSG_PARAMS_STR);
kk_service_deleteKey_handle(deviceCode->valuestring,paramStr);
dm_msg_thing_event_post(deviceCode->valuestring,MSG_KEYDELETE_NOTIFICATION);
} }
else{ else{
INFO_PRINT("Error msgtype!!! \n"); INFO_PRINT("Error msgtype!!! \n");
......
...@@ -20,6 +20,18 @@ typedef enum{ ...@@ -20,6 +20,18 @@ typedef enum{
DB_DEVTYPE DB_DEVTYPE
}; };
typedef enum{
DB_LOCKKEY_IDX = 0,
DB_LOCKKEY_DEVICECODE,
DB_LOCKKEY_KEYID,
DB_LOCKKEY_KEYTYPE,
DB_LOCKKEY_KEYROLE,
DB_LOCKKEY_ISVALID,
DB_LOCKKEY_KEYNAME,
DB_LOCKKEY_KEYEFFECTIVE,
DB_LOCKKEY_KEYEXPIRE
};
static kk_property_db_ctx_t s_kk_property_db_ctx = {0}; static kk_property_db_ctx_t s_kk_property_db_ctx = {0};
static kk_property_db_ctx_t *_kk_property_db_get_ctx(void) static kk_property_db_ctx_t *_kk_property_db_get_ctx(void)
{ {
...@@ -48,29 +60,47 @@ static int kk_property_db_Init(void) ...@@ -48,29 +60,47 @@ static int kk_property_db_Init(void)
_kk_property_db_lock(); _kk_property_db_lock();
ctx->pDb = g_kk_pDb; ctx->pDb = g_kk_pDb;
INFO_PRINT("property db Database opened\n");
{
const char *pPrpertyTable = "CREATE TABLE IF NOT EXISTS PropertiesInfo( \ const char *pPrpertyTable = "CREATE TABLE IF NOT EXISTS PropertiesInfo( \
idx INTEGER PRIMARY KEY, \ idx INTEGER PRIMARY KEY, \
deviceCode varchar(33), \ deviceCode varchar(33), \
identifier varchar(33), \ identifier varchar(33), \
value varchar(33), \ value varchar(33), \
valueType INTEGER, \ valueType INTEGER, \
devType INTEGER)"; devType INTEGER)";
char *pcErr; char *pcErr;
// DBG_vPrintf(DBG_SQL, "Execute SQL: '%s'\n", pConditionTableDef); // DBG_vPrintf(DBG_SQL, "Execute SQL: '%s'\n", pConditionTableDef);
if (sqlite3_exec(ctx->pDb, pPrpertyTable, NULL, NULL, &pcErr) != SQLITE_OK) if (sqlite3_exec(ctx->pDb, pPrpertyTable, NULL, NULL, &pcErr) != SQLITE_OK)
{ {
ERROR_PRINT("Error creating table (%s)\n", pcErr); ERROR_PRINT("Error creating table (%s)\n", pcErr);
sqlite3_free(pcErr); sqlite3_free(pcErr);
//eUtils_LockUnlock(&sLock); //eUtils_LockUnlock(&sLock);
_kk_property_db_unlock(); _kk_property_db_unlock();
return FAIL_RETURN; return FAIL_RETURN;
}
} }
const char *pLockKeys = "CREATE TABLE IF NOT EXISTS LockKeysInfo( \
idx INTEGER PRIMARY KEY, \
deviceCode varchar(33), \
KeyID varchar(10), \
KeyType INTEGER, \
KeyRole INTEGER, \
IsValid INTEGER, \
KeyName varchar(255), \
KeyEffectiveTime INTEGER, \
KeyExpiryTime INTEGER)";
if (sqlite3_exec(ctx->pDb, pLockKeys, 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); //eUtils_LockUnlock(&sLock);
_kk_property_db_unlock(); _kk_property_db_unlock();
...@@ -120,9 +150,6 @@ static int _kk_check_property_exist(const char* deviceCode,const char* identifie ...@@ -120,9 +150,6 @@ static int _kk_check_property_exist(const char* deviceCode,const char* identifie
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
_kk_property_db_unlock(); _kk_property_db_unlock();
return isExist; return isExist;
} }
int kk_property_db_insert(const char *deviceCode,const char *identifier,kk_tsl_data_type_e valuetype,int devtype) int kk_property_db_insert(const char *deviceCode,const char *identifier,kk_tsl_data_type_e valuetype,int devtype)
...@@ -164,7 +191,7 @@ int kk_property_db_update_value(const char *deviceCode,const char *identifier,co ...@@ -164,7 +191,7 @@ int kk_property_db_update_value(const char *deviceCode,const char *identifier,co
_kk_property_db_lock(); _kk_property_db_lock();
sqlCmd = sqlite3_mprintf("UPDATE PropertiesInfo SET value='%s' WHERE deviceCode= '%s' and identifier = '%s'",value,deviceCode,identifier); sqlCmd = sqlite3_mprintf("UPDATE PropertiesInfo SET value='%s' WHERE deviceCode= '%s' and identifier = '%s'",value,deviceCode,identifier);
DEBUG_PRINT("kk_property_db_update_value sqlCmd:%s\n",sqlCmd); //DEBUG_PRINT("kk_property_db_update_value sqlCmd:%s\n",sqlCmd);
rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg); rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( rc != SQLITE_OK ){ if( rc != SQLITE_OK ){
...@@ -354,7 +381,7 @@ int kk_property_sync_values(const char *deviceCode) ...@@ -354,7 +381,7 @@ int kk_property_sync_values(const char *deviceCode)
double value_double = atof(valueStr); double value_double = atof(valueStr);
res = kk_tsl_set_value(kk_tsl_set_property_value,node->dev_shadow,pIdentifier,&value_double,NULL); res = kk_tsl_set_value(kk_tsl_set_property_value,node->dev_shadow,pIdentifier,&value_double,NULL);
} }
else{ else if(valueType == KK_TSL_DATA_TYPE_TEXT || valueType == KK_TSL_DATA_TYPE_DATE){
res = kk_tsl_set_value(kk_tsl_set_property_value,node->dev_shadow,pIdentifier,NULL,valueStr); res = kk_tsl_set_value(kk_tsl_set_property_value,node->dev_shadow,pIdentifier,NULL,valueStr);
} }
if(res != SUCCESS_RETURN) if(res != SUCCESS_RETURN)
...@@ -419,4 +446,91 @@ int kk_property_delete_by_identify(char *identify) ...@@ -419,4 +446,91 @@ int kk_property_delete_by_identify(char *identify)
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
static int _kk_check_lockkey_exist(const char* deviceCode,const char* keyId)
{
int isExist = 0;
sqlite3_stmt *stmt;
char *pDeviceCode = NULL;
char *pKeyId = NULL;
kk_property_db_ctx_t *ctx = _kk_property_db_get_ctx();
const char *searchCmd = "select * from LockKeysInfo;";
_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 = sqlite3_column_text(stmt, DB_LOCKKEY_DEVICECODE);
pKeyId = sqlite3_column_text(stmt, DB_LOCKKEY_KEYID);
if(!strcmp(deviceCode,pDeviceCode)&&!strcmp(pKeyId,keyId))
{
isExist = 1;
break;
}
}
//INFO_PRINT("\n");
sqlite3_finalize(stmt);
_kk_property_db_unlock();
return isExist;
}
int kk_property_update_lockkeys(char deviceCode[DEVICE_CODE_MAXLEN],char *keyId,int KeyType, int KeyRole, \
int IsValid,char *KeyName,int KeyEffectiveTime,int KeyExpiryTime)
{
kk_property_db_ctx_t *ctx = _kk_property_db_get_ctx();
char *zErrMsg = 0;
int rc = 0;
char *sqlCmd = NULL;
if(_kk_check_lockkey_exist(deviceCode,keyId)){
sqlCmd = sqlite3_mprintf("UPDATE LockKeysInfo SET KeyType='%d', IsValid='%d', KeyRole='%d', \
KeyName='%s', KeyEffectiveTime='%d', KeyExpiryTime='%d' WHERE deviceCode= '%s' and KeyID = '%s'",KeyType,IsValid,KeyRole,KeyName,
KeyEffectiveTime,KeyExpiryTime,deviceCode,keyId);
}
else{
const char *insertCmd = "insert into LockKeysInfo (deviceCode,KeyID,KeyType,KeyRole,IsValid,KeyName,KeyEffectiveTime,KeyExpiryTime) \
values ('%s','%s','%d','%d','%d','%s','%d',%d);";
sqlCmd = sqlite3_mprintf(insertCmd,deviceCode,keyId,KeyType,KeyRole,IsValid,KeyName,KeyEffectiveTime,KeyExpiryTime);
}
_kk_property_db_lock();
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;
}
int kk_property_delete_lockkeys(char deviceCode[DEVICE_CODE_MAXLEN],char *keyId)
{
const char *deleteCmd = "delete from LockKeysInfo where deviceCode = '%s' and KeyID = '%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,keyId);
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;
}
......
...@@ -33,7 +33,10 @@ char * g_filerToPlatTable[] = ...@@ -33,7 +33,10 @@ char * g_filerToPlatTable[] =
{KK_THING_SERVICE_SETLOCALTIMER}, {KK_THING_SERVICE_SETLOCALTIMER},
{KK_THING_SERVICE_GETLOCALTIMER}, {KK_THING_SERVICE_GETLOCALTIMER},
{KK_THING_SERVICE_SETCOUNTDOWN}, {KK_THING_SERVICE_SETCOUNTDOWN},
{KK_THING_SERVICE_GETCOUNTDOWN}, {KK_THING_SERVICE_GETCOUNTDOWN},
{KK_THING_SERVICE_ADDKEY},
{KK_THING_SERVICE_DELETEKEY},
{KK_THING_SERVICE_MODIFYKEY}
}; };
static int _kk_filter_to_plat(const char* msgtype) static int _kk_filter_to_plat(const char* msgtype)
{ {
...@@ -617,7 +620,6 @@ void *udp_dispatch_yield(void *args){ ...@@ -617,7 +620,6 @@ void *udp_dispatch_yield(void *args){
DEBUG_PRINT("lan recmsg: %s\n", szDec); DEBUG_PRINT("lan recmsg: %s\n", szDec);
//DEBUG_PRINT("udp client ip:%s ,port is :%d htons(UDP_LAN_PORT)=%d \n",inet_ntoa(from.sin_addr),from.sin_port, htons(UDP_LAN_PORT)); //DEBUG_PRINT("udp client ip:%s ,port is :%d htons(UDP_LAN_PORT)=%d \n",inet_ntoa(from.sin_addr),from.sin_port, htons(UDP_LAN_PORT));
#ifdef test_
//"search_kk_ccu|deviceCode=1122334455667788;protocol=tcp" //"search_kk_ccu|deviceCode=1122334455667788;protocol=tcp"
if(strstr(szDec, "search_kk_ccu|") != NULL){ if(strstr(szDec, "search_kk_ccu|") != NULL){
...@@ -684,86 +686,6 @@ void *udp_dispatch_yield(void *args){ ...@@ -684,86 +686,6 @@ void *udp_dispatch_yield(void *args){
// DEBUG_PRINT("udp client is not local ip , refused send ack to it\n"); // DEBUG_PRINT("udp client is not local ip , refused send ack to it\n");
//} //}
} }
#else
json=cJSON_Parse(szDec);
if (!json) {
ERROR_PRINT("Error before: [%s]\n","cJSON_Parse");
}
else
{
infoObj = cJSON_GetObjectItem(json, "info");
payloadObj = cJSON_GetObjectItem(json, "payload");
if (infoObj != NULL && payloadObj != NULL){
msgtype = cJSON_GetObjectItem(infoObj, "msgtype");
if (msgtype == NULL || strstr(msgtype->valuestring, "/thing/topo/add") == NULL){
ERROR_PRINT("msgtype parameter is error \n");
cJSON_Delete(json);
continue;
}
proCode = cJSON_GetObjectItem(infoObj, "productCode");
devCode = cJSON_GetObjectItem(infoObj, "deviceCode");
params = cJSON_GetObjectItem(payloadObj, "params");
if (proCode == NULL || devCode == NULL || params == NULL){
ERROR_PRINT("productType productCode deviceCode params parameters are error \n");
cJSON_Delete(json);
continue;
}
macstr = cJSON_GetObjectItem(params, "mac");
if (macstr == NULL){
ERROR_PRINT("mac parameter is error \n");
cJSON_Delete(json);
continue;
}
INFO_PRINT(" productCode deviceCode mac: [%s][%s][%s] \n", proCode->valuestring,
devCode->valuestring, macstr->valuestring);
char device_code[DEVICE_CODE_LEN] = {0};
HAL_GetDevice_Code(device_code);
int res = kk_mid_subdev_add(KK_DM_DEVICE_GATEWAY, proCode->valuestring, devCode->valuestring,macstr->valuestring, device_code);
if (res != SUCCESS_RETURN) {
WARNING_PRINT("dm_mgr_gw_create error");
}
//kk_ipc_send(IPC_MID2APP, szDec, size);
memset(host_ip, 0, sizeof(host_ip));
memset(mac, 0, sizeof(mac));
memset(szOut, 0, sizeof(szOut));
HAL_Get_IP(host_ip,"ens33");
HAL_Get_mac(mac);
sprintf(szOut,"/thing/topo/add_reply|mac=%s;ip=%s",mac,host_ip);
DEBUG_PRINT("szOut:%s\n",szOut);
DEBUG_PRINT("udp client ip:%s ,port is :%d \n",inet_ntoa(from.sin_addr),from.sin_port);
//sendto(sock, szOut, strlen(szOut), 0, (struct sockaddr*)&from,len);
addrto_host.sin_addr.s_addr = inet_addr(inet_ntoa(from.sin_addr));
addrto_host.sin_port = htons(UDP_LAN_PORT_HOST);
//addrto_host.sin_port = from.sin_port;
if(strcmp(host_ip,inet_ntoa(from.sin_addr)) == 0)
{
sendto(sock_host, szOut, strlen(szOut), 0, (struct sockaddr*)&addrto_host,sizeof(addrto_host));
}
else
{
DEBUG_PRINT("udp client is not local ip , refused send ack to it\n");
}
}else{
INFO_PRINT("error format json: [%s]\n",szDec);
}
cJSON_Delete(json);
}
#endif
} }
usleep(100000); usleep(100000);
...@@ -886,27 +808,44 @@ int main(const int argc, const char **argv) ...@@ -886,27 +808,44 @@ int main(const int argc, const char **argv)
for (;;) { for (;;) {
usleep(200000); usleep(200000);
kk_platMsg_dispatch(); kk_platMsg_dispatch();
/*if (ct == 0){ /*
if (ct == 0){
ct =1; ct =1;
void* buf = "{\ void* buf = "{\
\"info\": {\ \"info\": {\
\"msgtype\": \"/thing/topo/add\",\ \"msgtype\": \"/thing/service/property/post\",\
\"productType\": \"gw\",\ \"productCode\": \"130\",\
\"productCode\": \"2\",\ \"deviceCode\": \"086BD7FFFE916442\"\
\"deviceCode\": \"1122334455667788\"\
},\ },\
\"payload\": {\ \"payload\": {\
\"msgId\": \"1\",\ \"msgId\": \"1\",\
\"version\": \"1.0\",\ \"version\": \"1.0\",\
\"params\": {\ \"params\": {\
\"deviceCode\": \"588E81FFFED3834A\",\ \"LockKeys\": [\
\"productCode\": \"24\",\ {\
\"mac\": \"588E81FFFED3834A\"\ \"KeyID\": \"1\",\
\"KeyType\": 0, \
\"KeyRole\": 0, \
\"IsValid\": 1, \
\"KeyName\": \"test1\", \
\"KeyEffectiveTime\": 0, \
\"KeyExpiryTime\": 1 \
},\
{\
\"KeyID\": \"2\",\
\"KeyType\": 1, \
\"KeyRole\": 1, \
\"IsValid\": 1, \
\"KeyName\": \"test2\", \
\"KeyEffectiveTime\": 3, \
\"KeyExpiryTime\": 4 \
} \
]\
}\ }\
}\ }\
}"; }";
kk_platMsg_handle(buf, "1122334455667788"); kk_platMsg_handle(buf, "086BD7FFFE916442");
//kk_set_tsl_by_productKey("a1OYuSallan","model.json"); //kk_set_tsl_by_productKey("a1OYuSallan","model.json");
//kk_mid_subdev_add("a1OYuSallan","allanWno8yDdsjCX15iq","","aabbccddeeff1122"); //kk_mid_subdev_add("a1OYuSallan","allanWno8yDdsjCX15iq","","aabbccddeeff1122");
}*/ }*/
......
...@@ -41,7 +41,7 @@ typedef struct kk_timer_list{ ...@@ -41,7 +41,7 @@ typedef struct kk_timer_list{
static kk_timer_info_t *p_timer_info_list = NULL; static kk_timer_info_t *p_timer_info_list = NULL;
static kk_timer_ctx_t s_kk_timer_ctx = {NULL,0,0}; static kk_timer_ctx_t s_kk_timer_ctx = {NULL,NULL,0,0};
static kk_timer_ctx_t *_kk_timer_get_ctx(void) static kk_timer_ctx_t *_kk_timer_get_ctx(void)
{ {
...@@ -68,11 +68,19 @@ void *kk_timer_yield(void *args) ...@@ -68,11 +68,19 @@ void *kk_timer_yield(void *args)
uint64_t current_time = 0; uint64_t current_time = 0;
kk_timer_info_t *ptr = NULL,*ptemp = NULL; kk_timer_info_t *ptr = NULL,*ptemp = NULL;
while (1) { while (1) {
current_time = HAL_GetTime();
_kk_timer_lock();
kk_del_expired_timer_from_list(current_time);
kk_timer_info_t *ptr = p_timer_info_list; ptr = p_timer_info_list;
while(ptr){ while(ptr){
if(current_time >= ptr->startTime && current_time < ptr->endTime && ptr->isEnable && ptr->isValid){
/*****do action*******/
}
ptr = ptr->next;
} }
_kk_timer_unlock();
sleep(5); sleep(5);
} }
...@@ -208,6 +216,8 @@ int kk_add_timer_to_list(uint64_t startTime,uint64_t endTime,int isValid, int is ...@@ -208,6 +216,8 @@ int kk_add_timer_to_list(uint64_t startTime,uint64_t endTime,int isValid, int is
{ {
kk_timer_info_t *ptr = NULL,*ptemp = NULL; kk_timer_info_t *ptr = NULL,*ptemp = NULL;
_kk_timer_lock();
ptemp = ptr = p_timer_info_list; ptemp = ptr = p_timer_info_list;
while(ptr){ while(ptr){
ptemp = ptr; ptemp = ptr;
...@@ -215,6 +225,7 @@ int kk_add_timer_to_list(uint64_t startTime,uint64_t endTime,int isValid, int is ...@@ -215,6 +225,7 @@ int kk_add_timer_to_list(uint64_t startTime,uint64_t endTime,int isValid, int is
} }
ptr = (kk_timer_info_t*)malloc(sizeof(kk_timer_info_t)); ptr = (kk_timer_info_t*)malloc(sizeof(kk_timer_info_t));
if(ptr == NULL){ if(ptr == NULL){
_kk_timer_unlock();
return FAIL_RETURN; return FAIL_RETURN;
} }
memcpy(ptr->deviceCode,deviceCode,strlen(deviceCode)); memcpy(ptr->deviceCode,deviceCode,strlen(deviceCode));
...@@ -228,30 +239,78 @@ int kk_add_timer_to_list(uint64_t startTime,uint64_t endTime,int isValid, int is ...@@ -228,30 +239,78 @@ int kk_add_timer_to_list(uint64_t startTime,uint64_t endTime,int isValid, int is
}else{ }else{
ptemp->next = ptr; ptemp->next = ptr;
} }
_kk_timer_unlock();
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
#if 0
int kk_del_expired_timer_from_list(uint64_t current)
{
kk_timer_info_t *ptr = NULL,*ptemp = NULL;
if(p_timer_info_list == NULL){
return FAIL_RETURN;
}
if(p_timer_info_list->endTime <= current){
ptr = p_timer_info_list;
p_timer_info_list = p_timer_info_list->next;
free(ptr);
ptr = NULL;
return SUCCESS_RETURN;
}
else{
ptr = p_timer_info_list->next;
ptemp = p_timer_info_list;
while(ptr){
if(ptr->endTime <= current){
ptemp->next = ptr->next;
free(ptr);
ptr = NULL;
return SUCCESS_RETURN;
}
ptemp = ptr;
ptr = ptr->next;
}
}
int kk_del_timer_from_list(uint64_t startTime,uint64_t endTime,const char *deviceCode) return FAIL_RETURN;
}
#endif
int kk_del_expired_timer_from_list(uint64_t current)
{ {
kk_timer_info_t *ptr = NULL,*ptemp = NULL; kk_timer_info_t *ptr = NULL,*ptemp = NULL;
ptemp = ptr = p_timer_info_list; if(p_timer_info_list == NULL){
return FAIL_RETURN;
}
ptr = p_timer_info_list;
while(ptr){ while(ptr){
ptemp = ptr; if(ptr->endTime <= current){
if(strcmp(ptr->deviceCode,deviceCode) ==0 && \ if(ptr == p_timer_info_list){
ptr->startTime == startTime && \ ptemp = p_timer_info_list;
ptr->endTime == endTime){ p_timer_info_list = p_timer_info_list->next;
free(ptemp);
ptemp = NULL;
ptr = p_timer_info_list;
}
else{
ptemp->next = ptr->next; ptemp->next = ptr->next;
free(ptr); free(ptr);
ptr = NULL; ptr = NULL;
return SUCCESS_RETURN; ptr = ptemp->next;
} }
}
ptr = ptr->next; else{
ptemp = ptr;
ptr = ptr->next;
}
} }
return FAIL_RETURN;
return SUCCESS_RETURN;
} }
...@@ -1027,16 +1027,32 @@ int kk_tsl_set_value(kk_tsl_set_t set, kk_tsl_t * dev_shadow, const char *identi ...@@ -1027,16 +1027,32 @@ int kk_tsl_set_value(kk_tsl_set_t set, kk_tsl_t * dev_shadow, const char *identi
const char *value_str) const char *value_str)
{ {
int res = 0; int res = 0;
char tmp[128] = {0};
int index = 0;
kk_tsl_event_t *property = NULL;
char *e_identifier = NULL;
kk_tsl_api_ctx_t *kk_tsl_api_ctx = _kk_tsl_api_get_ctx(); kk_tsl_api_ctx_t *kk_tsl_api_ctx = _kk_tsl_api_get_ctx();
if ( identifier == NULL || (value == NULL && value_str == NULL)) { if ( identifier == NULL || (value == NULL && value_str == NULL)) {
ERROR_PRINT("Invalid Parameter"); ERROR_PRINT("Invalid Parameter");
return FAIL_RETURN; return FAIL_RETURN;
} }
_kk_tsl_api_lock(); _kk_tsl_api_lock();
switch (set) { switch (set) {
case kk_tsl_set_property_value: { case kk_tsl_set_property_value: {
for (index = 0; index < dev_shadow->event_number; index++) {
property = dev_shadow->events + index;
if(strcmp(property->identifier,"property") == 0 ||
strcmp(property->identifier,"post") == 0){
e_identifier = property->identifier;
break;
}
}
sprintf(tmp,"%s.%s",e_identifier,identifier);
_kk_set_event_output_value(dev_shadow, (char *)tmp, strlen(tmp), (void *)value,
(char *)value_str);
res = _kk_tsl_set_property_value(dev_shadow, (char *)identifier, strlen(identifier), (void *)value, res = _kk_tsl_set_property_value(dev_shadow, (char *)identifier, strlen(identifier), (void *)value,
(char*)value_str); (char*)value_str);
} }
...@@ -1186,27 +1202,25 @@ static int kk_tsl_post_property_start(_IN_ kk_tsl_t * dev_shadow, _OU_ void **ha ...@@ -1186,27 +1202,25 @@ static int kk_tsl_post_property_start(_IN_ kk_tsl_t * dev_shadow, _OU_ void **ha
*handle = (void *)dapi_property; *handle = (void *)dapi_property;
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
static int _kk_tsl_get_property_by_index(_IN_ kk_tsl_t *dev_shadow, _IN_ int index, _OU_ kk_tsl_data_t **property)
{
int res = 0;
if (dev_shadow == NULL || index < 0) {
return INVALID_PARAMETER;
}
*property = (kk_tsl_data_t *)(dev_shadow->properties + index);
return SUCCESS_RETURN;
}
int kk_tsl_get_property_number(_IN_ kk_tsl_t *shadow, _OU_ int *number) int kk_tsl_get_property_number(_IN_ kk_tsl_t *shadow, _OU_ int *number)
{ {
int res = 0; int res = 0;
int index = 0;
kk_tsl_event_t *property = NULL;
if (shadow == NULL || number == NULL) { if (shadow == NULL || number == NULL) {
return INVALID_PARAMETER; return INVALID_PARAMETER;
} }
*number = shadow->property_number; for (index = 0; index < shadow->event_number; index++) {
return SUCCESS_RETURN; property = shadow->events + index;
if(strcmp(property->identifier,"property") == 0 ||
strcmp(property->identifier,"post") == 0){
*number = property->output_data_number;
return SUCCESS_RETURN;
}
}
*number = 0;
return FAIL_RETURN;
} }
static int _kk_tsl_post_property_add(_IN_ void *handle, _IN_ char *identifier, _IN_ int identifier_len) static int _kk_tsl_post_property_add(_IN_ void *handle, _IN_ char *identifier, _IN_ int identifier_len)
...@@ -1235,6 +1249,8 @@ int kk_tsl_post_property_add(_IN_ void *handle, _IN_ char *identifier, _IN_ int ...@@ -1235,6 +1249,8 @@ int kk_tsl_post_property_add(_IN_ void *handle, _IN_ char *identifier, _IN_ int
kk_tsl_data_t *property_refer = NULL; kk_tsl_data_t *property_refer = NULL;
char *identifier_refer = NULL; char *identifier_refer = NULL;
dm_api_property_t *dapi_property = NULL; dm_api_property_t *dapi_property = NULL;
kk_tsl_event_t *event = NULL;
kk_tsl_data_t *pEventoutput = NULL;
if (handle == NULL) { if (handle == NULL) {
return INVALID_PARAMETER; return INVALID_PARAMETER;
...@@ -1250,22 +1266,21 @@ int kk_tsl_post_property_add(_IN_ void *handle, _IN_ char *identifier, _IN_ int ...@@ -1250,22 +1266,21 @@ int kk_tsl_post_property_add(_IN_ void *handle, _IN_ char *identifier, _IN_ int
return ret; return ret;
} }
res = kk_tsl_get_property_number(dapi_property->shadow, &number); for (index = 0; index < dapi_property->shadow->event_number; index++) {
if (res != SUCCESS_RETURN) { event = dapi_property->shadow->events + index;
return FAIL_RETURN; if(strcmp(event->identifier,"property") == 0 ||
strcmp(event->identifier,"post") == 0){
pEventoutput = (kk_tsl_data_t *)(event->output_datas);
number = event->output_data_number;
break;
}
} }
for (index = 0; index < number; index++) { for (index = 0; index < number; index++) {
property_refer = NULL; property_refer = NULL;
identifier_refer = NULL; identifier_refer = NULL;
property_refer = pEventoutput+index;
res = _kk_tsl_get_property_by_index(dapi_property->shadow, index, &property_refer);
if (res != SUCCESS_RETURN) {
continue;
}
identifier_refer = property_refer->identifier; identifier_refer = property_refer->identifier;
res = _kk_tsl_post_property_add(handle, identifier_refer, strlen(identifier_refer)); res = _kk_tsl_post_property_add(handle, identifier_refer, strlen(identifier_refer));
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
ret = FAIL_RETURN; ret = FAIL_RETURN;
......
...@@ -366,12 +366,12 @@ static int _kk_tsl_opt_parse(_IN_ kk_tsl_data_value_t *data_value, _IN_ lite_cjs ...@@ -366,12 +366,12 @@ static int _kk_tsl_opt_parse(_IN_ kk_tsl_data_value_t *data_value, _IN_ lite_cjs
if(res == SUCCESS_RETURN){ if(res == SUCCESS_RETURN){
data_value->mix = atoi(lite_item.value); data_value->mix = atoi(lite_item.value);
printf("------------>[%s][%d]data_value->mix:%d\n",__FUNCTION__,__LINE__,data_value->mix); //printf("------------>[%s][%d]data_value->mix:%d\n",__FUNCTION__,__LINE__,data_value->mix);
} }
res = lite_cjson_object_item(root, KK_TSL_KEY_MAX, strlen(KK_TSL_KEY_MAX), &lite_item); res = lite_cjson_object_item(root, KK_TSL_KEY_MAX, strlen(KK_TSL_KEY_MAX), &lite_item);
if(res == SUCCESS_RETURN){ if(res == SUCCESS_RETURN){
data_value->max = atoi(lite_item.value); data_value->max = atoi(lite_item.value);
printf("------------>[%s][%d]data_value->max:%d\n",__FUNCTION__,__LINE__,data_value->max); //printf("------------>[%s][%d]data_value->max:%d\n",__FUNCTION__,__LINE__,data_value->max);
} }
} }
...@@ -1478,29 +1478,35 @@ static int _kk_tsl_data_insert_json_item(_IN_ kk_tsl_data_t *data, _IN_ lite_cjs ...@@ -1478,29 +1478,35 @@ static int _kk_tsl_data_insert_json_item(_IN_ kk_tsl_data_t *data, _IN_ lite_cjs
int kk_tsl_assemble_property(_IN_ kk_tsl_t *shadow, _IN_ char *identifier, _IN_ int identifier_len, int kk_tsl_assemble_property(_IN_ kk_tsl_t *shadow, _IN_ char *identifier, _IN_ int identifier_len,
_IN_ lite_cjson_item_t *lite) _IN_ lite_cjson_item_t *lite)
{ {
int res = 0, index = 0; int res = 0, index = 0,indexE = 0;
kk_tsl_data_t *property = NULL; kk_tsl_event_t *property = NULL;
kk_tsl_data_t *output_data = NULL;
if (shadow == NULL || identifier == NULL || identifier_len <= 0 || lite == NULL || lite->type != cJSON_Object) { if (shadow == NULL || identifier == NULL || identifier_len <= 0 || lite == NULL || lite->type != cJSON_Object) {
return INVALID_PARAMETER; return INVALID_PARAMETER;
} }
for (index = 0; index < shadow->property_number; index++) { for (index = 0; index < shadow->event_number; index++) {
property = shadow->properties + index; property = shadow->events + index;
if(strcmp(property->identifier,"property") == 0 ||
if ((strlen(property->identifier) == identifier_len) && strcmp(property->identifier,"post") == 0){
(memcmp(property->identifier, identifier, identifier_len) == 0)) { for(indexE = 0; indexE < property->output_data_number;indexE++){
/* dm_log_debug("Property Found: %.*s",identifier_len,identifier); */ output_data = property->output_datas + indexE;
break; if ((strlen(output_data->identifier) == identifier_len) &&
} (memcmp(output_data->identifier, identifier, identifier_len) == 0)) {
} /* dm_log_debug("Property Found: %.*s",identifier_len,identifier); */
break;
}
if (indexE == property->output_data_number) {
printf("Property Not Found: %.*s\n", identifier_len, identifier);
return FAIL_RETURN;
}
}
if (index == shadow->property_number) { }
printf("Property Not Found: %.*s\n", identifier_len, identifier);
return FAIL_RETURN;
} }
res = _kk_tsl_data_insert_json_item(property, lite); res = _kk_tsl_data_insert_json_item(output_data, lite);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
return FAIL_RETURN; return FAIL_RETURN;
} }
......
{
"schema":"https://iotx-tsl.oss-ap-southeast-1.aliyuncs.com/schema.json",
"profile":{
"productKey":"a1h88DsZIaY"
},
"services":[
{
"outputData":[
],
"identifier":"set",
"inputData":[
{
"identifier":"LightStatus",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"工作状态"
},
{
"identifier":"LightAdjustLevel",
"dataType":{
"specs":{
"unit":"%",
"min":"0",
"max":"100",
"step":"1"
},
"type":"int"
},
"name":"调光等级"
},
{
"identifier":"LightAlias",
"dataType":{
"specs":{
"length":"32"
},
"type":"text"
},
"name":"别名"
}
],
"method":"thing.service.property.set",
"name":"set",
"required":true,
"callType":"async",
"desc":"属性设置"
},
{
"outputData":[
{
"identifier":"LightStatus",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"工作状态"
},
{
"identifier":"LightAdjustLevel",
"dataType":{
"specs":{
"unit":"%",
"min":"0",
"max":"100",
"step":"1"
},
"type":"int"
},
"name":"调光等级"
},
{
"identifier":"LightAlias",
"dataType":{
"specs":{
"length":"32"
},
"type":"text"
},
"name":"别名"
}
],
"identifier":"get",
"inputData":[
"LightStatus",
"LightAdjustLevel",
"LightAlias"
],
"method":"thing.service.property.get",
"name":"get",
"required":true,
"callType":"async",
"desc":"属性获取"
}
],
"properties":[
{
"identifier":"LightStatus",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"工作状态",
"accessMode":"rw",
"required":false
},
{
"identifier":"LightAdjustLevel",
"dataType":{
"specs":{
"unit":"%",
"min":"0",
"max":"100",
"step":"1"
},
"type":"int"
},
"name":"调光等级",
"accessMode":"rw",
"required":false,
"desc":"调光等级采用百分比表示"
},
{
"identifier":"LightAlias",
"dataType":{
"specs":{
"length":"32"
},
"type":"text"
},
"name":"别名",
"accessMode":"rw",
"required":false
}
],
"events":[
{
"outputData":[
{
"identifier":"LightStatus",
"dataType":{
"specs":{
"0":"关闭",
"1":"打开"
},
"type":"bool"
},
"name":"工作状态"
},
{
"identifier":"LightAdjustLevel",
"dataType":{
"specs":{
"unit":"%",
"min":"0",
"max":"100",
"step":"1"
},
"type":"int"
},
"name":"调光等级"
},
{
"identifier":"LightAlias",
"dataType":{
"specs":{
"length":"32"
},
"type":"text"
},
"name":"别名"
}
],
"identifier":"post",
"method":"thing.event.property.post",
"name":"post",
"type":"info",
"required":true,
"desc":"属性上报"
},
{
"outputData":[
{
"identifier":"ErrorCode",
"dataType":{
"specs":{
"0":"恢复正常"
},
"type":"enum"
},
"name":"故障代码"
}
],
"identifier":"Error",
"method":"thing.event.Error.post",
"name":"故障上报",
"type":"alert",
"required":false
},
{
"outputData":[
],
"identifier":"TamperAlarm",
"method":"thing.event.TamperAlarm.post",
"name":"防撬报警",
"type":"alert",
"required":false
}
]
}
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