Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
k-sdk
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈伟灿
k-sdk
Commits
d59b0f9c
Commit
d59b0f9c
authored
Aug 21, 2020
by
chen.weican
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】调整msgType采用字串格式,统一业务API接口
【提交人】陈伟灿
parent
c02ee8a2
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
141 additions
and
126 deletions
+141
-126
application/kcloud/kcloud_data_handle.c
application/kcloud/kcloud_data_handle.c
+49
-47
application/kcloud/kk_topic_mng.c
application/kcloud/kk_topic_mng.c
+15
-14
midware/midware/dm/dm_ota.c
midware/midware/dm/dm_ota.c
+3
-1
midware/midware/dm/kk_dm_mng.c
midware/midware/dm/kk_dm_mng.c
+41
-36
midware/midware/dm/kk_dm_mng.h
midware/midware/dm/kk_dm_mng.h
+2
-3
midware/midware/dm/kk_dm_msg.c
midware/midware/dm/kk_dm_msg.c
+16
-14
midware/midware/dm/kk_dm_msg.h
midware/midware/dm/kk_dm_msg.h
+7
-0
midware/midware/dm/kk_linkkit.c
midware/midware/dm/kk_linkkit.c
+8
-11
No files found.
application/kcloud/kcloud_data_handle.c
View file @
d59b0f9c
...
...
@@ -18,24 +18,9 @@
#define KK_FILTER_SET_TOPIC_REPLY "/thing/service/property/set_reply"
#define KK_FILTER_EVENT_POST_TOPIC "/thing/event/property/post"
#define KK_FILTER_EVENT_POST_REPLY "/thing/event/property/post_reply"
const
char
DM_MSG_TO_MIDDWARE
[]
=
"{
\"
msgtype
\"
:
\"
%
d
\"
,
\"
productTyp
e
\"
:
\"
%s
\"
,
\"
deviceCode
\"
:
\"
%s
\"
}"
;
const
char
DM_MSG_TO_MIDDWARE
[]
=
"{
\"
msgtype
\"
:
\"
%
s
\"
,
\"
productType
\"
:
\"
%s
\"
,
\"
productCod
e
\"
:
\"
%s
\"
,
\"
deviceCode
\"
:
\"
%s
\"
}"
;
#define KK_TOPIC_SERVICE_DELIMITER '/'
typedef
struct
{
char
*
str
;
kk_msg_type_t
type
;
}
kk_topic_type_map_t
;
kk_topic_type_map_t
g_type_map
[]
=
{
{
"register_reply"
,
MSG_REGISTER_REPLY
},
{
"add_reply"
,
MSG_TOPOADD_REPLY
},
{
"login_reply"
,
MSG_LOGIN_REPLY
},
{
"offline_reply"
,
MSG_OFFLINE_REPLY
},
{
"/ota/device/upgrade"
,
MSG_OTA_UPGRADE
},
{
"thing/service/property/set"
,
MSG_PROPERTYSET
},
};
int
_kk_sendto_cloud
(
cJSON
*
root
)
{
cJSON
*
info
,
*
pData
;
...
...
@@ -51,6 +36,7 @@ int _kk_sendto_cloud(cJSON *root)
}
pData
=
cJSON_GetObjectItem
(
root
,
MSG_PAYLOAD_STR
);
if
(
pData
==
NULL
){
free
(
topic
);
return
-
1
;
}
INFO_PRINT
(
"[%s][%d] payload:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
pData
->
valuestring
);
...
...
@@ -108,25 +94,40 @@ static int _check_invalid_topic(const char* topic)
}
return
0
;
}
static
kk_msg_type_t
_kk_parse_type
(
const
char
*
topic
)
static
int
_kk_topic_parse_msgType
(
_IN_
char
*
topic
,
_IN_
int
start_deli
,
_OU_
char
**
msgTypeStr
)
{
int
num
=
0
,
idx
=
0
;
if
(
topic
==
NULL
){
return
MSG_INVALID
;
}
num
=
sizeof
(
g_type_map
)
/
sizeof
(
kk_topic_type_map_t
);
for
(
idx
=
0
;
idx
<
num
;
idx
++
){
if
(
strstr
(
topic
,
g_type_map
[
idx
].
str
)
!=
NULL
){
return
g_type_map
[
idx
].
type
;
}
int
res
=
0
,
start
=
0
,
len
=
0
,
slice
=
0
;
char
*
msgTypeStr_tmp
=
NULL
;
if
(
topic
==
NULL
)
{
return
-
1
;
}
res
=
kk_utils_memtok
(
topic
,
strlen
(
topic
),
KK_TOPIC_SERVICE_DELIMITER
,
start_deli
,
&
start
);
if
(
res
!=
0
)
{
return
-
1
;
}
len
=
strlen
(
topic
)
-
start
+
1
;
msgTypeStr_tmp
=
(
char
*
)
malloc
(
len
+
1
);
if
(
msgTypeStr_tmp
==
NULL
){
ERROR_PRINT
(
"[%s][%d]malloc fail!!!
\n
"
,
__FUNCTION__
,
__LINE__
);
return
-
1
;
}
return
MSG_INVALID
;
memcpy
(
msgTypeStr_tmp
,
topic
+
start
,
len
);
*
msgTypeStr
=
msgTypeStr_tmp
;
INFO_PRINT
(
"[%s][%d]%s
\n
"
,
__FUNCTION__
,
__LINE__
,
*
msgTypeStr
);
/* dm_log_debug("URI Product Key: %.*s, Device Name: %.*s", slice - start - 1, uri + start + 1, end - slice - 1,
uri + slice + 1); */
return
0
;
}
static
int
_kk_topic_parse_pkdn
(
_IN_
char
*
topic
,
_IN_
int
start_deli
,
_IN_
int
end_deli
,
_OU_
char
productType
[
PRODUCT_TYPE_LEN
],
_OU_
char
deviceCode
[
DEVICE_CODE_LEN
])
static
int
_kk_topic_parse_pkdn
(
_IN_
char
*
topic
,
_IN_
int
start_deli
,
_OU_
char
productType
[
PRODUCT_TYPE_LEN
],
_OU_
char
productCode
[
PRODUCT_CODE_LEN
],
_OU_
char
deviceCode
[
DEVICE_CODE_LEN
])
{
int
res
=
0
,
start
=
0
,
end
=
0
,
slice
=
0
;
int
res
=
0
,
start
=
0
,
end
=
0
,
slice
=
0
,
slice1
=
0
;
if
(
topic
==
NULL
||
productType
==
NULL
||
deviceCode
==
NULL
)
{
return
-
1
;
...
...
@@ -139,16 +140,18 @@ static int _kk_topic_parse_pkdn(_IN_ char *topic, _IN_ int start_deli, _IN_ int
if
(
res
!=
0
)
{
return
-
1
;
}
res
=
kk_utils_memtok
(
topic
,
strlen
(
topic
),
KK_TOPIC_SERVICE_DELIMITER
,
end_deli
,
&
end
);
res
=
kk_utils_memtok
(
topic
,
strlen
(
topic
),
KK_TOPIC_SERVICE_DELIMITER
,
start_deli
+
2
,
&
slice1
);
if
(
res
!=
0
)
{
return
-
1
;
}
res
=
kk_utils_memtok
(
topic
,
strlen
(
topic
),
KK_TOPIC_SERVICE_DELIMITER
,
start_deli
+
3
,
&
end
);
if
(
res
!=
0
)
{
return
-
1
;
}
/* dm_log_debug("URI Product Key: %.*s, Device Name: %.*s", slice - start - 1, uri + start + 1, end - slice - 1,
uri + slice + 1); */
memcpy
(
productType
,
topic
+
start
+
1
,
slice
-
start
-
1
);
memcpy
(
deviceCode
,
topic
+
slice
+
1
,
end
-
slice
-
1
);
memcpy
(
productCode
,
topic
+
slice
+
1
,
slice1
-
slice
-
1
);
memcpy
(
deviceCode
,
topic
+
slice1
+
1
,
end
-
slice1
-
1
);
return
0
;
}
...
...
@@ -160,30 +163,29 @@ static char * _kk_data_create(const char *topic,const char *data)
char
*
infoStr
=
NULL
;
int
infoStr_len
=
0
;
int
res
=
0
;
char
product_key
[
PRODUCT_TYPE_LEN
]
=
{
0
};
char
device_name
[
DEVICE_CODE_LEN
]
=
{
0
};
kk_msg_type_t
type
;
type
=
_kk_parse_type
(
topic
);
if
(
type
==
MSG_INVALID
){
ERROR_PRINT
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
return
NULL
;
}
res
=
_kk_topic_parse_pkdn
((
char
*
)
topic
,
2
,
4
,
product_key
,
device_name
);
infoStr_len
=
strlen
(
DM_MSG_TO_MIDDWARE
)
+
strlen
(
product_key
)
+
strlen
(
device_name
)
+
10
;
char
productType
[
PRODUCT_TYPE_LEN
]
=
{
0
};
char
productCode
[
PRODUCT_CODE_LEN
]
=
{
0
};
char
deviceCode
[
DEVICE_CODE_LEN
]
=
{
0
};
char
*
msgStr
=
NULL
;
res
=
_kk_topic_parse_pkdn
((
char
*
)
topic
,
2
,
productType
,
productCode
,
deviceCode
);
res
|=
_kk_topic_parse_msgType
((
char
*
)
topic
,
5
,
&
msgStr
);
infoStr_len
=
strlen
(
DM_MSG_TO_MIDDWARE
)
+
strlen
(
productType
)
+
strlen
(
productCode
)
+
strlen
(
deviceCode
)
+
strlen
(
msgStr
)
+
10
;
infoStr
=
malloc
(
infoStr_len
);
if
(
infoStr
==
NULL
){
ERROR_PRINT
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
free
(
msgStr
);
return
NULL
;
}
memset
(
infoStr
,
0x0
,
infoStr_len
);
snprintf
(
infoStr
,
infoStr_len
,
DM_MSG_TO_MIDDWARE
,
type
,
product_key
,
device_nam
e
);
snprintf
(
infoStr
,
infoStr_len
,
DM_MSG_TO_MIDDWARE
,
msgStr
,
productType
,
productCode
,
deviceCod
e
);
root
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
root
,
MSG_INFO_STR
,
infoStr
);
cJSON_AddStringToObject
(
root
,
MSG_PAYLOAD_STR
,
data
);
out
=
cJSON_Print
(
root
);
cJSON_Delete
(
root
);
free
(
msgStr
);
free
(
infoStr
);
INFO_PRINT
(
"[%s][%d]%s
\n
"
,
__FUNCTION__
,
__LINE__
,
out
);
return
out
;
...
...
application/kcloud/kk_topic_mng.c
View file @
d59b0f9c
...
...
@@ -9,7 +9,7 @@
const
char
KK_URI_SYS_PREFIX
[]
=
"/sys/kk/%s/%s/#"
;
const
char
KK_URI_SYS_PREFIX_EX
[]
=
"/sys/kk/%s/%s
/
"
;
const
char
KK_URI_SYS_PREFIX_EX
[]
=
"/sys/kk/%s/%s"
;
const
char
DM_URI_THING_SUB_REGISTER
[]
=
"thing/sub/register"
;
const
char
DM_URI_THING_SUB_UNREGISTER
[]
=
"thing/sub/unregister"
;
const
char
DM_URI_THING_TOPO_ADD
[]
=
"thing/topo/add"
;
...
...
@@ -130,27 +130,21 @@ static int _kk_utils_topic(_IN_ const char *name, _IN_ char *product_code,
return
0
;
}
static
int
_kk_utils_topic_ota
(
_IN_
int
type
,
_IN_
char
*
product_code
,
_IN_
char
*
device_code
,
_OU_
char
**
topic
)
static
int
_kk_utils_topic_ota
(
_IN_
char
*
str
,
_OU_
char
**
topic
)
{
int
service_name_len
=
0
;
int
*
pstr_uri
=
NULL
;
if
(
product_code
==
NULL
||
device_code
==
NULL
||
topic
==
NULL
||
*
topic
!=
NULL
)
{
if
(
str
==
NULL
||
topic
==
NULL
||
*
topic
!=
NULL
)
{
return
-
1
;
}
if
(
type
=
0
){
pstr_uri
=
KK_URI_OTA_PROCESS
;
}
else
if
(
type
=
1
){
pstr_uri
=
KK_URI_OTA_INFORM
;
}
service_name_len
=
strlen
(
pstr_uri
)
+
strlen
(
product_code
)
+
strlen
(
device_code
)
+
1
;
service_name_len
=
strlen
(
str
)
+
1
;
*
topic
=
malloc
(
service_name_len
);
if
(
*
topic
==
NULL
)
{
return
-
1
;
}
memset
(
*
topic
,
0
,
service_name_len
);
snprintf
(
*
topic
,
service_name_len
,
pstr_uri
,
product_code
,
device_code
);
memcpy
(
*
topic
,
str
,
service_name_len
);
return
0
;
}
...
...
@@ -158,7 +152,6 @@ static int _kk_utils_topic(_IN_ const char *name, _IN_ char *product_code,
char
*
KK_Make_Topic
(
cJSON
*
info
)
{
cJSON
*
type
,
*
product_code
,
*
device_code
,
*
root
;
kk_msg_type_t
msgtype
;
char
*
topic
=
NULL
;
root
=
cJSON_Parse
((
char
*
)
info
->
valuestring
);
...
...
@@ -174,7 +167,14 @@ char* KK_Make_Topic(cJSON *info)
if
(
device_code
==
NULL
){
goto
errorreturn
;
}
msgtype
=
atoi
(
type
->
valuestring
);
if
(
strstr
(
type
->
valuestring
,
"/ota/device/inform"
)){
_kk_utils_topic_ota
(
type
->
valuestring
,
&
topic
);
}
else
{
_kk_utils_topic
(
type
->
valuestring
,
product_code
->
valuestring
,
device_code
->
valuestring
,
&
topic
);
}
#if 0
switch(msgtype)
{
case MSG_REGISTER:
...
...
@@ -255,6 +255,7 @@ char* KK_Make_Topic(cJSON *info)
break;
}
#endif
INFO_PRINT
(
"[%s][%d] TOPIC:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
topic
);
cJSON_Delete
(
root
);
return
topic
;
...
...
midware/midware/dm/dm_ota.c
View file @
d59b0f9c
...
...
@@ -5,6 +5,8 @@
#include "dm_ota.h"
#include "cJSON.h"
#include "kk_dm_api.h"
#include "kk_dm_msg.h"
#include "com_api.h"
...
...
@@ -191,7 +193,7 @@ void dm_ota_handle(void *data){
payload
=
cJSON_GetObjectItem
(
json
,
MSG_PAYLOAD_STR
);
printf
(
" payload= %s
\n
"
,
payload
->
valuestring
);
if
(
atoi
(
typeJson
->
valuestring
)
==
MSG_OTA_UPGRADE
){
if
(
strstr
(
typeJson
->
valuestring
,
KK_THING_OTA_DEVICE_UPGRADE
)
){
char
buf
[
128
]
=
{
0
};
int
len
=
128
;
if
(
dm_ota_check
(
payload
->
valuestring
,
strlen
(
payload
->
valuestring
)
+
1
,
IOTX_OTA_TOPIC_TYPE_DEVICE_UPGRATE
)
==
0
){
...
...
midware/midware/dm/kk_dm_mng.c
View file @
d59b0f9c
This diff is collapsed.
Click to expand it.
midware/midware/dm/kk_dm_mng.h
View file @
d59b0f9c
...
...
@@ -38,7 +38,7 @@ typedef struct {
int
devid
;
//const char *service_prefix;
//const char *service_name;
kk_msg_type_t
msgtype
;
char
*
msgTypeStr
;
char
identity
[
IDENTIFY_MAXLEN
];
char
productType
[
PRODUCT_TYPE_MAXLEN
];
char
productCode
[
PRODUCT_CODE_MAXLEN
];
...
...
@@ -49,8 +49,7 @@ typedef struct {
//iotx_cm_data_handle_cb callback;
}
dm_msg_request_t
;
typedef
struct
{
kk_msg_type_t
msgtype
;
char
identity
[
IDENTIFY_MAXLEN
];
char
*
msgTypeStr
;
char
productType
[
PRODUCT_TYPE_MAXLEN
];
char
productCode
[
PRODUCT_CODE_MAXLEN
];
char
deviceCode
[
DEVICE_CODE_MAXLEN
];
...
...
midware/midware/dm/kk_dm_msg.c
View file @
d59b0f9c
...
...
@@ -9,7 +9,7 @@
const
char
DM_MSG_REQUEST
[]
DM_READ_ONLY
=
"{
\"
msgId
\"
:
\"
%d
\"
,
\"
version
\"
:
\"
%s
\"
,
\"
params
\"
:%.*s,
\"
method
\"
:
\"
%s
\"
}"
;
const
char
DM_MSG_INFO
[]
DM_READ_ONLY
=
"{
\"
msgtype
\"
:
\"
%
d
\"
,
\"
productType
\"
:
\"
%s
\"
,
\"
productCode
\"
:
\"
%s
\"
,
\"
deviceCode
\"
:
\"
%s
\"
,
\"
identifier
\"
:
\"
%s
\"
}"
;
const
char
DM_MSG_INFO
[]
DM_READ_ONLY
=
"{
\"
msgtype
\"
:
\"
%
s
\"
,
\"
productType
\"
:
\"
%s
\"
,
\"
productCode
\"
:
\"
%s
\"
,
\"
deviceCode
\"
:
\"
%s
\"
}"
;
void
kk_sendData2app
(
void
*
info
,
void
*
payload
){
cJSON
*
root
=
cJSON_CreateObject
();
...
...
@@ -438,15 +438,15 @@ int dm_msg_request (_IN_ dm_msg_request_t *request)
snprintf
(
payload
,
payload_len
,
DM_MSG_REQUEST
,
request
->
msgid
,
DM_MSG_VERSION
,
request
->
params_len
,
request
->
params
,
request
->
method
);
req_info_len
=
strlen
(
DM_MSG_INFO
)
+
10
+
strlen
(
request
->
productType
)
+
strlen
(
request
->
productCode
)
+
strlen
(
request
->
deviceCode
)
+
strlen
(
request
->
identity
)
+
1
;
req_info_len
=
strlen
(
DM_MSG_INFO
)
+
10
+
strlen
(
request
->
productType
)
+
strlen
(
request
->
productCode
)
+
strlen
(
request
->
deviceCode
)
+
strlen
(
request
->
msgTypeStr
)
+
1
;
req_info
=
malloc
(
req_info_len
);
if
(
req_info
==
NULL
)
{
free
(
payload
);
return
MEMORY_NOT_ENOUGH
;
}
memset
(
req_info
,
0
,
req_info_len
);
snprintf
(
req_info
,
req_info_len
,
DM_MSG_INFO
,
request
->
msg
type
,
request
->
productType
,
request
->
productCode
,
request
->
deviceCode
,
request
->
identity
);
snprintf
(
req_info
,
req_info_len
,
DM_MSG_INFO
,
request
->
msg
TypeStr
,
request
->
productType
,
request
->
productCode
,
request
->
deviceCode
);
memset
(
&
lite
,
0
,
sizeof
(
lite_cjson_t
));
res
=
lite_cjson_parse
(
payload
,
payload_len
,
&
lite
);
...
...
@@ -500,7 +500,7 @@ int dm_msg_response(_IN_ kk_msg_request_payload_t *request, _IN_ kk_msg_response
snprintf
(
payload
,
payload_len
,
DM_MSG_RESPONSE_WITH_DATA
,
request
->
id
.
value_length
,
request
->
id
.
value
,
response
->
code
,
data_len
,
data
);
res_info_len
=
strlen
(
DM_MSG_INFO
)
+
10
+
strlen
(
response
->
productType
)
+
strlen
(
response
->
deviceCode
)
+
strlen
(
response
->
identity
)
+
1
;
res_info_len
=
strlen
(
DM_MSG_INFO
)
+
10
+
strlen
(
response
->
productType
)
+
strlen
(
response
->
productCode
)
+
strlen
(
response
->
deviceCode
)
+
strlen
(
response
->
msgTypeStr
)
+
1
;
res_info
=
malloc
(
res_info_len
);
if
(
res_info
==
NULL
)
{
free
(
payload
);
...
...
@@ -508,8 +508,8 @@ int dm_msg_response(_IN_ kk_msg_request_payload_t *request, _IN_ kk_msg_response
}
memset
(
res_info
,
0
,
res_info_len
);
snprintf
(
res_info
,
res_info_len
,
DM_MSG_INFO
,
response
->
msg
type
,
response
->
productType
,
response
->
deviceCode
,
response
->
identity
);
snprintf
(
res_info
,
res_info_len
,
DM_MSG_INFO
,
response
->
msg
TypeStr
,
response
->
productType
,
response
->
productCode
,
response
->
deviceCode
);
memset
(
&
lite
,
0
,
sizeof
(
lite_cjson_t
));
...
...
@@ -597,19 +597,21 @@ static int dm_msg_request_parse(_IN_ char *payload, _IN_ int payload_len, _OU_ k
return
SUCCESS_RETURN
;
}
const
char
DM_URI_THING_SERVICE_PROPERTY_SET_REPLY
[]
=
"/thing/service/property/set_reply"
;
int
dm_msg_thing_property_set_reply
(
char
productType
[
PRODUCT_TYPE_MAXLEN
],
char
deviceCode
[
DEVICE_CODE_MAXLEN
],
char
*
payload
,
unsigned
int
payload_len
,
int
dm_msg_thing_property_set_reply
(
char
deviceCode
[
DEVICE_CODE_MAXLEN
],
char
*
payload
,
unsigned
int
payload_len
,
void
*
context
){
kk_msg_request_payload_t
request
;
kk_msg_response_t
response
;
dm_mgr_dev_node_t
*
node
=
NULL
;
int
res
=
0
,
devid
=
0
;
memset
(
&
request
,
0
,
sizeof
(
kk_msg_request_payload_t
));
memset
(
&
response
,
0
,
sizeof
(
kk_msg_response_t
));
res
=
dm_mgr_
search_device_by_pkdn
(
productType
,
deviceCode
,
&
devid
);
res
=
dm_mgr_
get_device_by_mac
(
deviceCode
,
&
node
);
if
(
res
<
SUCCESS_RETURN
)
{
ERROR_PRINT
(
"dm_mgr_search_device_by_pkdn failed"
);
return
res
;
...
...
@@ -620,13 +622,13 @@ int dm_msg_thing_property_set_reply(char productType[PRODUCT_TYPE_MAXLEN], char
return
res
;
}
/* Response */
response
.
msgtype
=
MSG_SETREPLY
;
memset
(
response
.
identity
,
""
,
strlen
(
""
));
memcpy
(
response
.
productType
,
productType
,
strlen
(
productType
));
memcpy
(
response
.
deviceCode
,
deviceCode
,
strlen
(
deviceCode
));
response
.
msgTypeStr
=
DM_URI_THING_SERVICE_PROPERTY_SET_REPLY
;
memcpy
(
response
.
productType
,
node
->
productType
,
strlen
(
node
->
productType
));
memcpy
(
response
.
productCode
,
node
->
productCode
,
strlen
(
node
->
productCode
));
memcpy
(
response
.
deviceCode
,
node
->
deviceCode
,
strlen
(
node
->
deviceCode
));
response
.
code
=
(
res
==
SUCCESS_RETURN
)
?
(
IOTX_DM_ERR_CODE_SUCCESS
)
:
(
IOTX_DM_ERR_CODE_REQUEST_ERROR
);
dm_msg_response
(
&
request
,
&
response
,
"{}"
,
strlen
(
"{}"
),
NULL
);
return
SUCCESS_RETURN
;
}
midware/midware/dm/kk_dm_msg.h
View file @
d59b0f9c
...
...
@@ -41,6 +41,13 @@ typedef struct {
#define DM_MSG_VERSION "1.0"
const
char
DM_MSG_INFO
[]
DM_READ_ONLY
;
#define KK_REGISTER_TOPIC_REPLY "/thing/sub/register_reply"
#define KK_ADD_TOPIC_REPLY "/thing/topo/add_reply"
#define KK_LOGIN_TOPIC_REPLY "/thing/combine/login_reply"
#define KK_THING_SERVICE_PROPERTY_SET "/thing/service/property/set"
#define KK_THING_OTA_DEVICE_UPGRADE "/ota/device/upgrade"
//const char DM_URI_SYS_PREFIX[] DM_READ_ONLY = "/sys/%s/%s/";
...
...
midware/midware/dm/kk_linkkit.c
View file @
d59b0f9c
...
...
@@ -231,7 +231,6 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
cJSON
*
json
;
cJSON
*
info_root
,
*
info
;
cJSON
*
payload
,
*
typeJson
;
kk_msg_type_t
msgType
;
json
=
cJSON_Parse
(
data
);
if
(
json
==
NULL
)
{
WARNING_PRINT
(
"Error before: [%s]
\n
"
,
"cJSON_Parse"
);
...
...
@@ -241,9 +240,8 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
info
=
cJSON_Parse
(
info_root
->
valuestring
);
typeJson
=
cJSON_GetObjectItem
(
info
,
MSG_TYPE_STR
);
payload
=
cJSON_GetObjectItem
(
json
,
MSG_PAYLOAD_STR
);
msgType
=
atoi
(
typeJson
->
valuestring
);
if
(
msgType
==
MSG_REGISTER_REPLY
){
if
(
strstr
(
typeJson
->
valuestring
,
KK_REGISTER_TOPIC_REPLY
)
){
//====todo======
//get devicececret and save it
INFO_PRINT
(
" topic:register_reply
\n
"
);
...
...
@@ -257,7 +255,7 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
_iotx_linkkit_upstream_callback_remove
(
atoi
(
response
.
id
.
value
),
response
.
code
.
value_int
);
_iotx_linkkit_upstream_mutex_unlock
();
}
else
if
(
msgType
==
MSG_TOPOADD_REPLY
){
}
else
if
(
strstr
(
typeJson
->
valuestring
,
KK_ADD_TOPIC_REPLY
)
){
//====todo======
//
INFO_PRINT
(
" topic:add_reply
\n
"
);
...
...
@@ -271,7 +269,7 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
_iotx_linkkit_upstream_callback_remove
(
atoi
(
response
.
id
.
value
),
response
.
code
.
value_int
);
_iotx_linkkit_upstream_mutex_unlock
();
}
else
if
(
msgType
==
MSG_LOGIN_REPLY
){
}
else
if
(
strstr
(
typeJson
->
valuestring
,
KK_LOGIN_TOPIC_REPLY
)
){
//====todo======
//
INFO_PRINT
(
" topic:login_reply
\n
"
);
...
...
@@ -284,13 +282,12 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
_iotx_linkkit_upstream_mutex_lock
();
_iotx_linkkit_upstream_callback_remove
(
atoi
(
response
.
id
.
value
),
response
.
code
.
value_int
);
_iotx_linkkit_upstream_mutex_unlock
();
}
else
if
(
msgType
==
MSG_PROPERTYSET
){
INFO_PRINT
(
"property set reply
\n
"
);
cJSON
*
product_type
=
cJSON_GetObjectItem
(
info
,
MSG_PRODUCT_TYPE_STR
);
cJSON
*
device_name
=
cJSON_GetObjectItem
(
info
,
MSG_DEVICE_CODE_STR
);
dm_msg_thing_property_set_reply
(
product_type
->
valuestring
,
device_name
->
valuestring
,
payload
->
valuestring
,
strlen
(
payload
->
valuestring
),
NULL
);
}
else
if
(
strstr
(
typeJson
->
valuestring
,
KK_THING_SERVICE_PROPERTY_SET
)){
INFO_PRINT
(
"property set
\n
"
);
cJSON
*
deviceCode
=
cJSON_GetObjectItem
(
info
,
MSG_DEVICE_CODE_STR
);
dm_msg_thing_property_set_reply
(
deviceCode
->
valuestring
,
payload
->
valuestring
,
strlen
(
payload
->
valuestring
),
NULL
);
//kk_tsl_service_property_set(topic->valuestring, payload->valuestring, strlen(payload->valuestring), NULL);
}
else
if
(
msgType
==
MSG_OTA_UPGRADE
){
}
else
if
(
strstr
(
typeJson
->
valuestring
,
KK_THING_OTA_DEVICE_UPGRADE
)
){
INFO_PRINT
(
"ota upgrade...
\n
"
);
kk_dm_ota_send
(
data
,
strlen
(
data
)
+
1
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment