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
4a5ef433
Commit
4a5ef433
authored
Aug 14, 2020
by
chen.weican
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】对下行数据的topic处理,目前所有上行下行topic都已经移到APP层处理,以适应其他云平台的对接
【提交人】陈伟灿
parent
b6d1208b
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
255 additions
and
261 deletions
+255
-261
application/kcloud/kcloud_data_handle.c
application/kcloud/kcloud_data_handle.c
+95
-13
application/kcloud/kk_topic_mng.c
application/kcloud/kk_topic_mng.c
+6
-6
common/api/com_api.h
common/api/com_api.h
+19
-2
common/hal/kk_product.h
common/hal/kk_product.h
+1
-1
midware/midware/dm/dm_ota.c
midware/midware/dm/dm_ota.c
+33
-37
midware/midware/dm/kk_dm_msg.c
midware/midware/dm/kk_dm_msg.c
+3
-16
midware/midware/dm/kk_linkkit.c
midware/midware/dm/kk_linkkit.c
+71
-164
midware/midware/midware.c
midware/midware/midware.c
+26
-21
midware/midware/ota/iotx_ota.c
midware/midware/ota/iotx_ota.c
+1
-1
No files found.
application/kcloud/kcloud_data_handle.c
View file @
4a5ef433
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#include "mqtt_api.h"
#include "mqtt_api.h"
#include "com_api.h"
#include "com_api.h"
#include "cJSON.h"
#include "cJSON.h"
#include "kk_product.h"
#define KK_FILTER_ADD_TOPIC "/thing/topo/add"
#define KK_FILTER_ADD_TOPIC "/thing/topo/add"
#define KK_FILTER_ADD_TOPIC_REPLY "/thing/topo/add_reply"
#define KK_FILTER_ADD_TOPIC_REPLY "/thing/topo/add_reply"
...
@@ -17,6 +18,22 @@
...
@@ -17,6 +18,22 @@
#define KK_FILTER_SET_TOPIC_REPLY "/thing/service/property/set_reply"
#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_TOPIC "/thing/event/property/post"
#define KK_FILTER_EVENT_POST_REPLY "/thing/event/property/post_reply"
#define KK_FILTER_EVENT_POST_REPLY "/thing/event/property/post_reply"
const
char
DM_MSG_TO_MIDDWARE
[]
=
"{
\"
msgtype
\"
:
\"
%d
\"
,
\"
product_type
\"
:
\"
%s
\"
,
\"
device_name
\"
:
\"
%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
)
int
_kk_sendto_cloud
(
cJSON
*
root
)
...
@@ -24,21 +41,15 @@ int _kk_sendto_cloud(cJSON *root)
...
@@ -24,21 +41,15 @@ int _kk_sendto_cloud(cJSON *root)
cJSON
*
info
,
*
pData
;
cJSON
*
info
,
*
pData
;
char
*
topic
=
NULL
;
char
*
topic
=
NULL
;
char
*
payload
=
NULL
;
char
*
payload
=
NULL
;
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
info
=
cJSON_GetObjectItem
(
root
,
MSG_INFO_STR
);
info
=
cJSON_GetObjectItem
(
root
,
"info"
);
if
(
info
==
NULL
){
if
(
info
==
NULL
){
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
return
-
1
;
return
-
1
;
}
}
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
topic
=
KK_Make_Topic
(
info
);
topic
=
KK_Make_Topic
(
info
);
if
(
topic
==
NULL
){
if
(
topic
==
NULL
){
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
return
-
1
;
return
-
1
;
}
}
pData
=
cJSON_GetObjectItem
(
root
,
MSG_PAYLOAD_STR
);
pData
=
cJSON_GetObjectItem
(
root
,
"payload"
);
if
(
pData
==
NULL
){
if
(
pData
==
NULL
){
return
-
1
;
return
-
1
;
}
}
...
@@ -97,15 +108,83 @@ static int _check_invalid_topic(const char* topic)
...
@@ -97,15 +108,83 @@ static int _check_invalid_topic(const char* topic)
}
}
return
0
;
return
0
;
}
}
static
kk_msg_type_t
_kk_parse_type
(
const
char
*
topic
)
{
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
;
}
}
return
MSG_INVALID
;
}
static
int
_kk_topic_parse_pkdn
(
_IN_
char
*
topic
,
_IN_
int
start_deli
,
_IN_
int
end_deli
,
_OU_
char
product_key
[
PRODUCT_TYPE_LEN
],
_OU_
char
device_name
[
DEVICE_CODE_LEN
])
{
int
res
=
0
,
start
=
0
,
end
=
0
,
slice
=
0
;
if
(
topic
==
NULL
||
product_key
==
NULL
||
device_name
==
NULL
)
{
return
-
1
;
}
res
=
kk_utils_memtok
(
topic
,
strlen
(
topic
),
KK_TOPIC_SERVICE_DELIMITER
,
start_deli
,
&
start
);
if
(
res
!=
0
)
{
return
-
1
;
}
res
=
kk_utils_memtok
(
topic
,
strlen
(
topic
),
KK_TOPIC_SERVICE_DELIMITER
,
start_deli
+
1
,
&
slice
);
if
(
res
!=
0
)
{
return
-
1
;
}
res
=
kk_utils_memtok
(
topic
,
strlen
(
topic
),
KK_TOPIC_SERVICE_DELIMITER
,
end_deli
,
&
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
(
product_key
,
topic
+
start
+
1
,
slice
-
start
-
1
);
memcpy
(
device_name
,
topic
+
slice
+
1
,
end
-
slice
-
1
);
return
0
;
}
static
char
*
_kk_data_create
(
const
char
*
topic
,
const
char
*
data
)
static
char
*
_kk_data_create
(
const
char
*
topic
,
const
char
*
data
)
{
{
cJSON
*
root
;
cJSON
*
root
;
char
*
out
;
char
*
out
;
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
){
printf
(
"[%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
;
infoStr
=
malloc
(
infoStr_len
);
if
(
infoStr
==
NULL
){
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
return
NULL
;
}
memset
(
infoStr
,
0x0
,
infoStr_len
);
snprintf
(
infoStr
,
infoStr_len
,
DM_MSG_TO_MIDDWARE
,
type
,
product_key
,
device_name
);
root
=
cJSON_CreateObject
();
root
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
root
,
"topic"
,
topic
);
cJSON_AddStringToObject
(
root
,
MSG_INFO_STR
,
infoStr
);
cJSON_AddStringToObject
(
root
,
"payload"
,
data
);
cJSON_AddStringToObject
(
root
,
MSG_PAYLOAD_STR
,
data
);
out
=
cJSON_Print
(
root
);
out
=
cJSON_Print
(
root
);
cJSON_Delete
(
root
);
cJSON_Delete
(
root
);
free
(
infoStr
);
printf
(
"[%s][%d]%s
\n
"
,
__FUNCTION__
,
__LINE__
,
out
);
printf
(
"[%s][%d]%s
\n
"
,
__FUNCTION__
,
__LINE__
,
out
);
return
out
;
return
out
;
//free(out); /* Print to text, Delete the cJSON, print it, release the string. */
//free(out); /* Print to text, Delete the cJSON, print it, release the string. */
...
@@ -117,8 +196,11 @@ void KK_Sendto_DevData(const char *topic,const char *data)
...
@@ -117,8 +196,11 @@ void KK_Sendto_DevData(const char *topic,const char *data)
{
{
return
;
//ingore the message
return
;
//ingore the message
}
}
char
*
send_data
=
_kk_data_create
(
topic
,
data
);
printf
(
"[%s][%d]receive from cloud,topic:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
topic
);
printf
(
"[%s][%d]receive from cloud,topic:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
topic
);
char
*
send_data
=
_kk_data_create
(
topic
,
data
);
if
(
send_data
==
NULL
){
return
;
}
kk_ipc_send
(
IPC_APP2MID
,
send_data
,
strlen
(
send_data
)
+
1
);
kk_ipc_send
(
IPC_APP2MID
,
send_data
,
strlen
(
send_data
)
+
1
);
free
(
send_data
);
}
}
application/kcloud/kk_topic_mng.c
View file @
4a5ef433
...
@@ -135,15 +135,15 @@ char* KK_Make_Topic(cJSON *info)
...
@@ -135,15 +135,15 @@ char* KK_Make_Topic(cJSON *info)
char
*
topic
=
NULL
;
char
*
topic
=
NULL
;
root
=
cJSON_Parse
((
char
*
)
info
->
valuestring
);
root
=
cJSON_Parse
((
char
*
)
info
->
valuestring
);
type
=
cJSON_GetObjectItem
(
root
,
"msgtype"
);
type
=
cJSON_GetObjectItem
(
root
,
MSG_TYPE_STR
);
if
(
type
==
NULL
){
if
(
type
==
NULL
){
goto
errorreturn
;
goto
errorreturn
;
}
}
product_type
=
cJSON_GetObjectItem
(
root
,
"product_type"
);
product_type
=
cJSON_GetObjectItem
(
root
,
MSG_PRODUCT_TYPE_STR
);
if
(
product_type
==
NULL
){
if
(
product_type
==
NULL
){
goto
errorreturn
;
goto
errorreturn
;
}
}
device_name
=
cJSON_GetObjectItem
(
root
,
"device_name"
);
device_name
=
cJSON_GetObjectItem
(
root
,
MSG_DEVICE_NAME_STR
);
if
(
device_name
==
NULL
){
if
(
device_name
==
NULL
){
goto
errorreturn
;
goto
errorreturn
;
}
}
...
@@ -182,7 +182,7 @@ char* KK_Make_Topic(cJSON *info)
...
@@ -182,7 +182,7 @@ char* KK_Make_Topic(cJSON *info)
cJSON
*
identify
;
cJSON
*
identify
;
char
*
service_name
=
NULL
;
char
*
service_name
=
NULL
;
int
service_name_len
=
0
;
int
service_name_len
=
0
;
identify
=
cJSON_GetObjectItem
(
root
,
"identifier"
);
identify
=
cJSON_GetObjectItem
(
root
,
MSG_INDENTIFIER_STR
);
if
(
identify
==
NULL
){
if
(
identify
==
NULL
){
goto
errorreturn
;
goto
errorreturn
;
}
}
...
@@ -202,7 +202,7 @@ char* KK_Make_Topic(cJSON *info)
...
@@ -202,7 +202,7 @@ char* KK_Make_Topic(cJSON *info)
cJSON
*
identify
;
cJSON
*
identify
;
char
*
service_name
=
NULL
;
char
*
service_name
=
NULL
;
int
service_name_len
=
0
;
int
service_name_len
=
0
;
identify
=
cJSON_GetObjectItem
(
root
,
"identifier"
);
identify
=
cJSON_GetObjectItem
(
root
,
MSG_INDENTIFIER_STR
);
if
(
identify
==
NULL
){
if
(
identify
==
NULL
){
goto
errorreturn
;
goto
errorreturn
;
}
}
...
@@ -220,7 +220,7 @@ char* KK_Make_Topic(cJSON *info)
...
@@ -220,7 +220,7 @@ char* KK_Make_Topic(cJSON *info)
case
MSG_SETREPLY
:
case
MSG_SETREPLY
:
_kk_utils_topic
(
DM_URI_THING_SERVICE_PROPERTY_SET_REPLY
,
product_type
->
valuestring
,
device_name
->
valuestring
,
&
topic
);
_kk_utils_topic
(
DM_URI_THING_SERVICE_PROPERTY_SET_REPLY
,
product_type
->
valuestring
,
device_name
->
valuestring
,
&
topic
);
break
;
break
;
case
MSG_OTA
:
case
MSG_OTA
_PROCESS
:
_kk_utils_topic
(
KK_URI_OTA_PROCESS
,
product_type
->
valuestring
,
device_name
->
valuestring
,
&
topic
);
_kk_utils_topic
(
KK_URI_OTA_PROCESS
,
product_type
->
valuestring
,
device_name
->
valuestring
,
&
topic
);
break
;
break
;
...
...
common/api/com_api.h
View file @
4a5ef433
...
@@ -28,6 +28,7 @@ typedef enum {
...
@@ -28,6 +28,7 @@ typedef enum {
}
ipc_type
;
}
ipc_type
;
typedef
enum
{
typedef
enum
{
/******MIDDWARE TO APP**************/
MSG_REGISTER
=
0
,
MSG_REGISTER
=
0
,
MSG_UNREGISTER
,
MSG_UNREGISTER
,
MSG_TOPOADD
,
MSG_TOPOADD
,
...
@@ -40,9 +41,25 @@ typedef enum{
...
@@ -40,9 +41,25 @@ typedef enum{
MSG_EVENTPOST
,
MSG_EVENTPOST
,
MSG_SERVICERESPONSE
,
MSG_SERVICERESPONSE
,
MSG_SETREPLY
,
MSG_SETREPLY
,
MSG_OTA
,
MSG_OTA_PROCESS
,
/*******APP TO MIDDWARE**************/
MSG_REGISTER_REPLY
,
MSG_TOPOADD_REPLY
,
MSG_OFFLINE_REPLY
,
MSG_LOGIN_REPLY
,
MSG_PROPERTYSET
,
MSG_OTA_UPGRADE
,
MSG_INVALID
,
}
kk_msg_type_t
;
}
kk_msg_type_t
;
#define MSG_TYPE_STR "msgtype"
#define MSG_PRODUCT_TYPE_STR "product_type"
#define MSG_DEVICE_NAME_STR "device_name"
#define MSG_PAYLOAD_STR "payload"
#define MSG_INFO_STR "info"
#define MSG_INDENTIFIER_STR "identifier"
typedef
void
ipc_cb
(
void
*
data
,
int
len
);
typedef
void
ipc_cb
(
void
*
data
,
int
len
);
int
kk_ipc_init
(
ipc_type
type
,
ipc_cb
cb
);
int
kk_ipc_init
(
ipc_type
type
,
ipc_cb
cb
);
int
kk_ipc_dinit
();
int
kk_ipc_dinit
();
...
...
common/hal/kk_product.h
View file @
4a5ef433
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
#define PRODUCT_TYPE_LEN (32+1)
#define PRODUCT_TYPE_LEN (32+1)
#define PRODUCT_CODE_LEN (32+1)
#define PRODUCT_CODE_LEN (32+1)
#define DEVICE_CODE_LEN (
64
+1)
#define DEVICE_CODE_LEN (
32
+1)
#define MAC_ADDR_LEN_MAX (10)
#define MAC_ADDR_LEN_MAX (10)
#define PID_STRLEN_MAX (64)
#define PID_STRLEN_MAX (64)
#define MID_STRLEN_MAX (64)
#define MID_STRLEN_MAX (64)
...
...
midware/midware/dm/dm_ota.c
View file @
4a5ef433
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
#include "dm_ota.h"
#include "dm_ota.h"
#include "cJSON.h"
#include "cJSON.h"
#include "kk_dm_api.h"
#include "kk_dm_api.h"
#include "com_api.h"
static
dm_ota_ctx_t
g_dm_ota_ctx
;
static
dm_ota_ctx_t
g_dm_ota_ctx
;
...
@@ -82,20 +82,10 @@ int ota_uri_parse_pkdn(_IN_ char *uri, _IN_ int uri_len, _IN_ int start_deli, _I
...
@@ -82,20 +82,10 @@ int ota_uri_parse_pkdn(_IN_ char *uri, _IN_ int uri_len, _IN_ int start_deli, _I
}
}
int
dm_ota_setPKN
(
void
*
topic
)
int
dm_ota_setPKN
(
char
product_key
[
PRODUCT_KEY_MAXLEN
],
char
device_name
[
DEVICE_NAME_MAXLEN
]
)
{
{
dm_ota_ctx_t
*
ctx
=
_dm_ota_get_ctx
();
dm_ota_ctx_t
*
ctx
=
_dm_ota_get_ctx
();
char
product_key
[
PRODUCT_KEY_MAXLEN
]
=
{
0
};
char
device_name
[
DEVICE_NAME_MAXLEN
]
=
{
0
};
int
res
=
0
;
int
res
=
0
;
//ota topic:/ota/device/upgrade/{product_key}/{device_name}
res
=
ota_uri_parse_pkdn
((
char
*
)
topic
,
strlen
(
topic
),
4
,
6
,
product_key
,
device_name
);
if
(
res
!=
SUCCESS_RETURN
)
{
printf
(
"dm_ota_setPKN error
\n
"
);
return
FAIL_RETURN
;
}
memset
(
ctx
->
product_key
,
0
,
PRODUCT_KEY_MAXLEN
);
memset
(
ctx
->
product_key
,
0
,
PRODUCT_KEY_MAXLEN
);
memset
(
ctx
->
device_name
,
0
,
DEVICE_NAME_MAXLEN
);
memset
(
ctx
->
device_name
,
0
,
DEVICE_NAME_MAXLEN
);
memcpy
(
ctx
->
product_key
,
product_key
,
PRODUCT_KEY_MAXLEN
);
memcpy
(
ctx
->
product_key
,
product_key
,
PRODUCT_KEY_MAXLEN
);
...
@@ -183,24 +173,29 @@ void dm_ota_handle(void *data){
...
@@ -183,24 +173,29 @@ void dm_ota_handle(void *data){
printf
(
"dm_ota_handle ================== [%s]
\n
"
,
data
);
printf
(
"dm_ota_handle ================== [%s]
\n
"
,
data
);
char
*
out
;
char
*
out
;
int
res
=
0
;
int
res
=
0
;
cJSON
*
json
;
cJSON
*
json
,
*
info_root
,
*
info
;
cJSON
*
topic
;
cJSON
*
topic
,
*
typeJson
;
cJSON
*
payload
;
cJSON
*
payload
;
cJSON
*
product_type
,
*
device_name
;
json
=
cJSON_Parse
(
data
);
json
=
cJSON_Parse
(
data
);
if
(
!
json
)
{
if
(
json
==
NULL
)
{
printf
(
"Error before: [%s]
\n
"
,
"cJSON_Parse"
);
printf
(
"Error before: [%s]
\n
"
,
"cJSON_Parse"
);
return
;
}
}
else
{
topic
=
cJSON_GetObjectItem
(
json
,
"topic"
);
payload
=
cJSON_GetObjectItem
(
json
,
"payload"
);
printf
(
"topic: [%s] ,payload= %s
\n
"
,
topic
->
valuestring
,
payload
->
valuestring
);
info_root
=
cJSON_GetObjectItem
(
json
,
MSG_INFO_STR
);
if
(
strstr
(
topic
->
valuestring
,
"/ota/device/upgrade"
)
!=
NULL
){
info
=
cJSON_Parse
(
info_root
->
valuestring
);
typeJson
=
cJSON_GetObjectItem
(
info
,
MSG_TYPE_STR
);
product_type
=
cJSON_GetObjectItem
(
info
,
MSG_PRODUCT_TYPE_STR
);
device_name
=
cJSON_GetObjectItem
(
info
,
MSG_DEVICE_NAME_STR
);
payload
=
cJSON_GetObjectItem
(
json
,
MSG_PAYLOAD_STR
);
printf
(
" payload= %s
\n
"
,
payload
->
valuestring
);
if
(
atoi
(
typeJson
->
valuestring
)
==
MSG_OTA_UPGRADE
){
char
buf
[
128
]
=
{
0
};
char
buf
[
128
]
=
{
0
};
int
len
=
128
;
int
len
=
128
;
if
(
dm_ota_check
(
payload
->
valuestring
,
strlen
(
payload
->
valuestring
)
+
1
,
IOTX_OTA_TOPIC_TYPE_DEVICE_UPGRATE
)
==
0
){
if
(
dm_ota_check
(
payload
->
valuestring
,
strlen
(
payload
->
valuestring
)
+
1
,
IOTX_OTA_TOPIC_TYPE_DEVICE_UPGRATE
)
==
0
){
dm_ota_setPKN
(
topic
->
valuestring
);
dm_ota_setPKN
(
product_type
->
valuestring
,
device_name
->
valuestring
);
dm_fota_perform_sync
(
buf
,
len
);
dm_fota_perform_sync
(
buf
,
len
);
}
else
{
}
else
{
printf
(
"parse params error !!
\n
"
);
printf
(
"parse params error !!
\n
"
);
...
@@ -208,10 +203,11 @@ void dm_ota_handle(void *data){
...
@@ -208,10 +203,11 @@ void dm_ota_handle(void *data){
}
else
{
}
else
{
printf
(
"invaild ota topic: [%s]
\n
"
,
topic
->
valuestring
);
printf
(
"invaild ota type: [%d]
\n
"
,
atoi
(
typeJson
->
valuestring
)
);
}
}
cJSON_Delete
(
json
);
cJSON_Delete
(
json
);
}
cJSON_Delete
(
info
);
}
}
int
dm_ota_check
(
void
*
payload
,
int
len
,
iotx_ota_topic_types_t
type
){
int
dm_ota_check
(
void
*
payload
,
int
len
,
iotx_ota_topic_types_t
type
){
...
...
midware/midware/dm/kk_dm_msg.c
View file @
4a5ef433
...
@@ -569,33 +569,20 @@ static int dm_msg_request_parse(_IN_ char *payload, _IN_ int payload_len, _OU_ k
...
@@ -569,33 +569,20 @@ static int dm_msg_request_parse(_IN_ char *payload, _IN_ int payload_len, _OU_ k
}
}
int
dm_msg_thing_property_set_reply
(
c
onst
char
*
topic
,
const
char
*
payload
,
unsigned
int
payload_len
,
int
dm_msg_thing_property_set_reply
(
c
har
product_type
[
PRODUCT_KEY_MAXLEN
],
char
device_name
[
DEVICE_NAME_MAXLEN
],
char
*
payload
,
unsigned
int
payload_len
,
void
*
context
){
void
*
context
){
kk_msg_request_payload_t
request
;
kk_msg_request_payload_t
request
;
kk_msg_response_t
response
;
kk_msg_response_t
response
;
int
res
=
0
,
devid
=
0
;
int
res
=
0
,
devid
=
0
;
char
product_key
[
PRODUCT_KEY_MAXLEN
]
=
{
0
};
char
device_name
[
DEVICE_NAME_MAXLEN
]
=
{
0
};
memset
(
&
request
,
0
,
sizeof
(
kk_msg_request_payload_t
));
memset
(
&
request
,
0
,
sizeof
(
kk_msg_request_payload_t
));
memset
(
&
response
,
0
,
sizeof
(
kk_msg_response_t
));
memset
(
&
response
,
0
,
sizeof
(
kk_msg_response_t
));
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
/**************to do*******************/
res
=
dm_mgr_search_device_by_pkdn
(
product_type
,
device_name
,
&
devid
);
//dm_log_info(DM_URI_THING_SERVICE_PROPERTY_SET);
/* Request */
/* Request */
res
=
kk_msg_uri_parse_pkdn
((
char
*
)
topic
,
strlen
(
topic
),
2
+
KK_URI_OFFSET
,
4
+
KK_URI_OFFSET
,
product_key
,
device_name
);
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
res
=
dm_mgr_search_device_by_pkdn
(
product_key
,
device_name
,
&
devid
);
if
(
res
<
SUCCESS_RETURN
)
{
if
(
res
<
SUCCESS_RETURN
)
{
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
return
res
;
return
res
;
...
@@ -610,7 +597,7 @@ int dm_msg_thing_property_set_reply(const char *topic, const char *payload, unsi
...
@@ -610,7 +597,7 @@ int dm_msg_thing_property_set_reply(const char *topic, const char *payload, unsi
/* Response */
/* Response */
response
.
msgtype
=
MSG_SETREPLY
;
response
.
msgtype
=
MSG_SETREPLY
;
memset
(
response
.
identity
,
""
,
strlen
(
""
));
memset
(
response
.
identity
,
""
,
strlen
(
""
));
memcpy
(
response
.
product_key
,
product_
key
,
strlen
(
product_key
));
memcpy
(
response
.
product_key
,
product_
type
,
strlen
(
product_type
));
memcpy
(
response
.
device_name
,
device_name
,
strlen
(
device_name
));
memcpy
(
response
.
device_name
,
device_name
,
strlen
(
device_name
));
response
.
code
=
(
res
==
SUCCESS_RETURN
)
?
(
IOTX_DM_ERR_CODE_SUCCESS
)
:
(
IOTX_DM_ERR_CODE_REQUEST_ERROR
);
response
.
code
=
(
res
==
SUCCESS_RETURN
)
?
(
IOTX_DM_ERR_CODE_SUCCESS
)
:
(
IOTX_DM_ERR_CODE_REQUEST_ERROR
);
dm_msg_response
(
&
request
,
&
response
,
"{}"
,
strlen
(
"{}"
),
NULL
);
dm_msg_response
(
&
request
,
&
response
,
"{}"
,
strlen
(
"{}"
),
NULL
);
...
...
midware/midware/dm/kk_linkkit.c
View file @
4a5ef433
...
@@ -231,64 +231,68 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
...
@@ -231,64 +231,68 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
char
*
out
;
char
*
out
;
int
res
=
0
;
int
res
=
0
;
cJSON
*
json
;
cJSON
*
json
;
cJSON
*
topic
;
cJSON
*
info_root
,
*
info
;
cJSON
*
payload
;
cJSON
*
payload
,
*
typeJson
;
kk_msg_type_t
msgType
;
json
=
cJSON_Parse
(
data
);
json
=
cJSON_Parse
(
data
);
if
(
!
json
)
{
if
(
json
==
NULL
)
{
printf
(
"Error before: [%s]
\n
"
,
"cJSON_Parse"
);
printf
(
"Error before: [%s]
\n
"
,
"cJSON_Parse"
);
return
;
}
}
else
{
info_root
=
cJSON_GetObjectItem
(
json
,
MSG_INFO_STR
);
topic
=
cJSON_GetObjectItem
(
json
,
"topic"
);
info
=
cJSON_Parse
(
info_root
->
valuestring
);
payload
=
cJSON_GetObjectItem
(
json
,
"payload"
);
typeJson
=
cJSON_GetObjectItem
(
info
,
MSG_TYPE_STR
);
payload
=
cJSON_GetObjectItem
(
json
,
MSG_PAYLOAD_STR
);
msgType
=
atoi
(
typeJson
->
valuestring
);
printf
(
"topic: [%s] ,payload= %s
\n
"
,
topic
->
valuestring
,
payload
->
valuestring
);
if
(
msgType
==
MSG_REGISTER_REPLY
){
if
(
strstr
(
topic
->
valuestring
,
"register_reply"
)
!=
NULL
){
//====todo======
//====todo======
//get devicececret and save it
//get devicececret and save it
printf
(
" topic:register_reply
\n
"
);
printf
(
" topic:register_reply
\n
"
);
dm_msg_response_payload_t
response
;
dm_msg_response_payload_t
response
;
res
=
dm_msg_response_parse
((
char
*
)
payload
->
valuestring
,
strlen
(
payload
->
valuestring
)
+
1
,
&
response
);
res
=
dm_msg_response_parse
((
char
*
)
payload
->
valuestring
,
strlen
(
payload
->
valuestring
)
+
1
,
&
response
);
if
(
res
!=
SUCCESS_RETURN
)
{
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
goto
directReturn
;
}
}
_iotx_linkkit_upstream_mutex_lock
();
_iotx_linkkit_upstream_mutex_lock
();
_iotx_linkkit_upstream_callback_remove
(
atoi
(
response
.
id
.
value
),
response
.
code
.
value_int
);
_iotx_linkkit_upstream_callback_remove
(
atoi
(
response
.
id
.
value
),
response
.
code
.
value_int
);
_iotx_linkkit_upstream_mutex_unlock
();
_iotx_linkkit_upstream_mutex_unlock
();
}
else
if
(
strstr
(
topic
->
valuestring
,
"add_reply"
)
!=
NULL
){
}
else
if
(
msgType
==
MSG_TOPOADD_REPLY
){
//====todo======
//====todo======
//
//
printf
(
" topic:add_reply
\n
"
);
printf
(
" topic:add_reply
\n
"
);
dm_msg_response_payload_t
response
;
dm_msg_response_payload_t
response
;
res
=
dm_msg_response_parse
((
char
*
)
payload
->
valuestring
,
strlen
(
payload
->
valuestring
)
+
1
,
&
response
);
res
=
dm_msg_response_parse
((
char
*
)
payload
->
valuestring
,
strlen
(
payload
->
valuestring
)
+
1
,
&
response
);
if
(
res
!=
SUCCESS_RETURN
)
{
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
goto
directReturn
;
}
}
_iotx_linkkit_upstream_mutex_lock
();
_iotx_linkkit_upstream_mutex_lock
();
_iotx_linkkit_upstream_callback_remove
(
atoi
(
response
.
id
.
value
),
response
.
code
.
value_int
);
_iotx_linkkit_upstream_callback_remove
(
atoi
(
response
.
id
.
value
),
response
.
code
.
value_int
);
_iotx_linkkit_upstream_mutex_unlock
();
_iotx_linkkit_upstream_mutex_unlock
();
}
else
if
(
strstr
(
topic
->
valuestring
,
"login_reply"
)
!=
NULL
){
}
else
if
(
msgType
==
MSG_LOGIN_REPLY
){
//====todo======
//====todo======
//
//
printf
(
" topic:login_reply
\n
"
);
printf
(
" topic:login_reply
\n
"
);
dm_msg_response_payload_t
response
;
dm_msg_response_payload_t
response
;
res
=
dm_msg_response_parse
((
char
*
)
payload
->
valuestring
,
strlen
(
payload
->
valuestring
)
+
1
,
&
response
);
res
=
dm_msg_response_parse
((
char
*
)
payload
->
valuestring
,
strlen
(
payload
->
valuestring
)
+
1
,
&
response
);
if
(
res
!=
SUCCESS_RETURN
)
{
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
goto
directReturn
;
}
}
_iotx_linkkit_upstream_mutex_lock
();
_iotx_linkkit_upstream_mutex_lock
();
_iotx_linkkit_upstream_callback_remove
(
atoi
(
response
.
id
.
value
),
response
.
code
.
value_int
);
_iotx_linkkit_upstream_callback_remove
(
atoi
(
response
.
id
.
value
),
response
.
code
.
value_int
);
_iotx_linkkit_upstream_mutex_unlock
();
_iotx_linkkit_upstream_mutex_unlock
();
}
else
if
(
strstr
(
topic
->
valuestring
,
"thing/service/property/set"
)
!=
NULL
){
}
else
if
(
msgType
==
MSG_PROPERTYSET
){
printf
(
"property set reply
\n
"
);
printf
(
"property set reply
\n
"
);
dm_msg_thing_property_set_reply
(
topic
->
valuestring
,
payload
->
valuestring
,
strlen
(
payload
->
valuestring
),
NULL
);
cJSON
*
product_type
=
cJSON_GetObjectItem
(
info
,
MSG_PRODUCT_TYPE_STR
);
cJSON
*
device_name
=
cJSON_GetObjectItem
(
info
,
MSG_DEVICE_NAME_STR
);
dm_msg_thing_property_set_reply
(
product_type
->
valuestring
,
device_name
->
valuestring
,
payload
->
valuestring
,
strlen
(
payload
->
valuestring
),
NULL
);
//kk_tsl_service_property_set(topic->valuestring, payload->valuestring, strlen(payload->valuestring), NULL);
//kk_tsl_service_property_set(topic->valuestring, payload->valuestring, strlen(payload->valuestring), NULL);
}
else
if
(
strstr
(
topic
->
valuestring
,
"/ota/device/upgrade"
)
!=
NULL
){
}
else
if
(
msgType
==
MSG_OTA_UPGRADE
){
printf
(
"ota upgrade...
\n
"
);
printf
(
"ota upgrade...
\n
"
);
kk_dm_ota_send
(
data
,
strlen
(
data
)
+
1
);
kk_dm_ota_send
(
data
,
strlen
(
data
)
+
1
);
...
@@ -297,9 +301,12 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
...
@@ -297,9 +301,12 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
}
}
directReturn:
cJSON_Delete
(
json
);
cJSON_Delete
(
json
);
cJSON_Delete
(
info
);
}
#if 0
#if 0
int res = 0;
int res = 0;
void *callback;
void *callback;
...
@@ -996,106 +1003,6 @@ int kk_init_dmproc(){
...
@@ -996,106 +1003,6 @@ int kk_init_dmproc(){
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
#if 0
static int _iotx_linkkit_master_open(iotx_linkkit_dev_meta_info_t *meta_info)
{
int res = 0;
iotx_linkkit_ctx_t *ctx = _iotx_linkkit_get_ctx();
if (ctx->is_opened) {
return FAIL_RETURN;
}
ctx->is_opened = 1;
HAL_SetProductKey(meta_info->product_key);
HAL_SetProductSecret(meta_info->product_secret);
HAL_SetDeviceName(meta_info->device_name);
HAL_SetDeviceSecret(meta_info->device_secret);
/* Create Mutex */
ctx->mutex = HAL_MutexCreate();
if (ctx->mutex == NULL) {
dm_log_err("Not Enough Memory");
ctx->is_opened = 0;
return FAIL_RETURN;
}
ctx->upstream_mutex = HAL_MutexCreate();
if (ctx->upstream_mutex == NULL) {
HAL_MutexDestroy(ctx->mutex);
dm_log_err("Not Enough Memory");
ctx->is_opened = 0;
return FAIL_RETURN;
}
res = iotx_dm_open();
if (res != SUCCESS_RETURN) {
HAL_MutexDestroy(ctx->upstream_mutex);
HAL_MutexDestroy(ctx->mutex);
ctx->is_opened = 0;
return FAIL_RETURN;
}
INIT_LIST_HEAD(&ctx->upstream_sync_callback_list);
return SUCCESS_RETURN;
}
static int _iotx_linkkit_slave_open(iotx_linkkit_dev_meta_info_t *meta_info)
{
int res = 0, devid;
iotx_linkkit_ctx_t *ctx = _iotx_linkkit_get_ctx();
if (!ctx->is_opened) {
return FAIL_RETURN;
}
res = iotx_dm_subdev_create(meta_info->product_key, meta_info->device_name, meta_info->device_secret, &devid);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
return devid;
}
static int _iotx_linkkit_master_connect(void)
{
int res = 0;
iotx_linkkit_ctx_t *ctx = _iotx_linkkit_get_ctx();
iotx_dm_init_params_t dm_init_params;
iotx_dm_event_types_t type;
if (ctx->is_connected) {
return FAIL_RETURN;
}
ctx->is_connected = 1;
memset(&dm_init_params, 0, sizeof(iotx_dm_init_params_t));
dm_init_params.event_callback = _iotx_linkkit_event_callback;
res = iotx_dm_connect(&dm_init_params);
if (res != SUCCESS_RETURN) {
dm_log_err("DM Start Failed");
ctx->is_connected = 0;
return FAIL_RETURN;
}
res = iotx_dm_subscribe(IOTX_DM_LOCAL_NODE_DEVID);
if (res != SUCCESS_RETURN) {
dm_log_err("DM Subscribe Failed");
ctx->is_connected = 0;
return FAIL_RETURN;
}
type = IOTX_DM_EVENT_INITIALIZED;
_iotx_linkkit_event_callback(type, "{\"devid\":0}");
return SUCCESS_RETURN;
}
#endif
int
_iotx_linkkit_slave_connect
(
int
devid
)
int
_iotx_linkkit_slave_connect
(
int
devid
)
{
{
...
...
midware/midware/midware.c
View file @
4a5ef433
...
@@ -23,10 +23,10 @@ void mid_cb(void* data, int len){
...
@@ -23,10 +23,10 @@ void mid_cb(void* data, int len){
char
*
out
;
char
*
out
;
cJSON
*
json
;
cJSON
*
json
;
cJSON
*
topic
;
cJSON
*
info_root
,
*
info
,
*
type
;
cJSON
*
payload
;
cJSON
*
payload
;
cJSON
*
product_type
,
*
device_name
;
int
res
;
int
res
;
void
*
buf
=
malloc
(
len
);
void
*
buf
=
malloc
(
len
);
memcpy
(
buf
,
data
,
len
);
memcpy
(
buf
,
data
,
len
);
res
=
dm_queue_msg_insert
((
void
*
)
buf
);
res
=
dm_queue_msg_insert
((
void
*
)
buf
);
...
@@ -35,34 +35,40 @@ void mid_cb(void* data, int len){
...
@@ -35,34 +35,40 @@ void mid_cb(void* data, int len){
//return FAIL_RETURN;
//return FAIL_RETURN;
}
}
json
=
cJSON_Parse
(
data
);
json
=
cJSON_Parse
(
data
);
if
(
!
json
)
{
if
(
!
json
)
{
printf
(
"Error before: [%s]
\n
"
,
"cJSON_Parse"
);
printf
(
"Error before: [%s]
\n
"
,
"cJSON_Parse"
);
}
}
else
else
{
{
topic
=
cJSON_GetObjectItem
(
json
,
"topic"
);
info_root
=
cJSON_GetObjectItem
(
json
,
MSG_INFO_STR
);
if
(
topic
!=
NULL
&&
(
strstr
(
topic
->
valuestring
,
"register_reply"
)
!=
NULL
||
info
=
cJSON_Parse
(
info_root
->
valuestring
);
strstr
(
topic
->
valuestring
,
"add_reply"
)
!=
NULL
||
product_type
=
cJSON_GetObjectItem
(
info
,
MSG_PRODUCT_TYPE_STR
);
strstr
(
topic
->
valuestring
,
"login_reply"
)
!=
NULL
||
device_name
=
cJSON_GetObjectItem
(
info
,
MSG_DEVICE_NAME_STR
);
strstr
(
topic
->
valuestring
,
"offline_reply"
)
!=
NULL
||
type
=
cJSON_GetObjectItem
(
info
,
MSG_TYPE_STR
);
strstr
(
topic
->
valuestring
,
"/ota/device/upgrade"
)
!=
NULL
))
switch
(
atoi
(
type
->
valuestring
))
{
{
printf
(
"This topic don't send to platform: %s
\r\n
"
,
topic
->
valuestring
);
case
MSG_REGISTER_REPLY
:
case
MSG_TOPOADD_REPLY
:
case
MSG_LOGIN_REPLY
:
case
MSG_OTA_UPGRADE
:
case
MSG_OFFLINE_REPLY
:
printf
(
"This topic don't send to platform
\r\n
"
);
cJSON_Delete
(
info
);
return
;
return
;
default:
break
;
}
}
payload
=
cJSON_GetObjectItem
(
json
,
MSG_PAYLOAD_STR
);
payload
=
cJSON_GetObjectItem
(
json
,
"payload"
);
char
mac
[
DEVICE_MAC_MAXLEN
]
=
{
0
};
char
mac
[
DEVICE_MAC_MAXLEN
]
=
{
0
};
res
=
dm_mgr_search_mac_by_
topic
(
topic
->
valuestring
,
mac
);
res
=
dm_mgr_search_mac_by_
pkdn
(
product_type
->
valuestring
,
device_name
->
valuestring
,
mac
);
if
(
res
!=
SUCCESS_RETURN
)
{
if
(
res
!=
SUCCESS_RETURN
)
{
cJSON_Delete
(
json
);
cJSON_Delete
(
info
);
return
;
return
;
}
}
cJSON
*
jsonplay
=
cJSON_Parse
(
payload
->
valuestring
);
cJSON
*
jsonplay
=
cJSON_Parse
(
payload
->
valuestring
);
cJSON_AddStringToObject
(
jsonplay
,
"mac"
,
mac
);
cJSON_AddStringToObject
(
jsonplay
,
"mac"
,
mac
);
void
*
out
=
cJSON_Print
(
jsonplay
);
void
*
out
=
cJSON_Print
(
jsonplay
);
...
@@ -71,10 +77,9 @@ void mid_cb(void* data, int len){
...
@@ -71,10 +77,9 @@ void mid_cb(void* data, int len){
free
(
out
);
free
(
out
);
cJSON_Delete
(
jsonplay
);
cJSON_Delete
(
jsonplay
);
cJSON_Delete
(
json
);
cJSON_Delete
(
json
);
cJSON_Delete
(
info
);
}
}
}
}
}
}
...
...
midware/midware/ota/iotx_ota.c
View file @
4a5ef433
...
@@ -534,7 +534,7 @@ int OTA_publishProgress(void *handle, char* payload){
...
@@ -534,7 +534,7 @@ int OTA_publishProgress(void *handle, char* payload){
return
IOT_OTAE_INVALID_PARAM
;
return
IOT_OTAE_INVALID_PARAM
;
}
}
HAL_Snprintf
(
topicBuf
,
topicLen
,
DM_MSG_INFO
,
MSG_OTA
,
h_ota
->
product_key
,
h_ota
->
device_name
,
""
);
HAL_Snprintf
(
topicBuf
,
topicLen
,
DM_MSG_INFO
,
MSG_OTA
_PROCESS
,
h_ota
->
product_key
,
h_ota
->
device_name
,
""
);
cJSON
*
root
=
cJSON_CreateObject
();
cJSON
*
root
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
root
,
"info"
,
topicBuf
);
cJSON_AddStringToObject
(
root
,
"info"
,
topicBuf
);
...
...
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