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
329075f9
Commit
329075f9
authored
Aug 13, 2020
by
chen.weican
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】调整topic的处理,所有topic在app层处理,以应对不同topic规则。
【提交人】陈伟灿
parent
e31335ef
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
161 additions
and
9 deletions
+161
-9
application/kcloud/kcloud_data_handle.c
application/kcloud/kcloud_data_handle.c
+19
-9
application/kcloud/kk_topic_mng.c
application/kcloud/kk_topic_mng.c
+142
-0
No files found.
application/kcloud/kcloud_data_handle.c
View file @
329075f9
...
@@ -21,25 +21,34 @@
...
@@ -21,25 +21,34 @@
int
_kk_sendto_cloud
(
cJSON
*
root
)
int
_kk_sendto_cloud
(
cJSON
*
root
)
{
{
cJSON
*
pTopic
,
*
pData
;
cJSON
*
info
,
*
pData
;
char
*
topic
=
NULL
;
char
*
topic
=
NULL
;
char
*
payload
=
NULL
;
char
*
payload
=
NULL
;
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
pTopic
=
cJSON_GetObjectItem
(
root
,
"topic"
);
info
=
cJSON_GetObjectItem
(
root
,
"info"
);
if
(
pTopic
==
NULL
){
if
(
info
==
NULL
){
printf
(
"[%s][%d] topic is null
\n
"
,
__FUNCTION__
,
__LINE__
);
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
return
;
return
-
1
;
}
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
topic
=
KK_Make_Topic
(
info
);
if
(
topic
==
NULL
){
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
return
-
1
;
}
}
pData
=
cJSON_GetObjectItem
(
root
,
"payload"
);
pData
=
cJSON_GetObjectItem
(
root
,
"payload"
);
if
(
pData
==
NULL
){
if
(
pData
==
NULL
){
printf
(
"[%s][%d] payload is null
\n
"
,
__FUNCTION__
,
__LINE__
);
return
-
1
;
return
;
}
}
printf
(
"[%s][%d] topic:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
pTopic
->
valuestring
);
printf
(
"[%s][%d] payload:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
pData
->
valuestring
);
printf
(
"[%s][%d] payload:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
pData
->
valuestring
);
KK_MQTT_SendMsg
(
pTopic
->
valuestring
,(
const
char
*
)
pData
->
valuestring
);
KK_MQTT_SendMsg
(
topic
,(
const
char
*
)
pData
->
valuestring
);
free
(
topic
);
return
0
;
}
}
void
KK_Data_FromDev
(
void
*
str
,
int
len
)
void
KK_Data_FromDev
(
void
*
str
,
int
len
)
{
{
cJSON
*
root
,
*
cmd
;
cJSON
*
root
,
*
cmd
;
...
@@ -110,5 +119,6 @@ void KK_Sendto_DevData(const char *topic,const char *data)
...
@@ -110,5 +119,6 @@ void KK_Sendto_DevData(const char *topic,const char *data)
}
}
char
*
send_data
=
_kk_data_create
(
topic
,
data
);
char
*
send_data
=
_kk_data_create
(
topic
,
data
);
printf
(
"[%s][%d]receive from cloud,topic:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
topic
);
kk_ipc_send
(
IPC_APP2MID
,
send_data
,
strlen
(
send_data
)
+
1
);
kk_ipc_send
(
IPC_APP2MID
,
send_data
,
strlen
(
send_data
)
+
1
);
}
}
application/kcloud/kk_topic_mng.c
View file @
329075f9
...
@@ -4,8 +4,22 @@
...
@@ -4,8 +4,22 @@
#include <string.h>
#include <string.h>
#include "kk_product.h"
#include "kk_product.h"
#include "cJSON.h"
#include "cJSON.h"
#include "com_api.h"
const
char
KK_URI_SYS_PREFIX
[]
=
"/sys/%s/%s/#"
;
const
char
KK_URI_SYS_PREFIX
[]
=
"/sys/%s/%s/#"
;
const
char
KK_URI_SYS_PREFIX_EX
[]
=
"/sys/%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"
;
const
char
DM_URI_THING_TOPO_DELETE
[]
=
"thing/topo/delete"
;
const
char
DM_URI_THING_TOPO_GET
[]
=
"thing/topo/get"
;
const
char
DM_URI_THING_LIST_FOUND
[]
=
"thing/list/found"
;
const
char
DM_URI_COMBINE_LOGIN
[]
=
"combine/login"
;
const
char
DM_URI_COMBINE_LOGOUT
[]
=
"combine/logout"
;
const
char
DM_URI_THING_EVENT_PROPERTY_POST
[]
=
"thing/event/property/post"
;
const
char
DM_URI_THING_EVENT_POST
[]
=
"thing/event/%.*s/post"
;
const
char
DM_URI_THING_SERVICE_RESPONSE
[]
=
"thing/service/%.*s_reply"
;
const
char
DM_URI_THING_SERVICE_PROPERTY_SET_REPLY
[]
=
"thing/service/property/set_reply"
;
const
char
KK_URI_OTA_PREFIX
[]
=
"/ota/device/upgrade/%s/%s/#"
;
const
char
KK_URI_OTA_PREFIX
[]
=
"/ota/device/upgrade/%s/%s/#"
;
...
@@ -88,5 +102,133 @@ int KK_Client_Gateway_Subscribe(void)
...
@@ -88,5 +102,133 @@ int KK_Client_Gateway_Subscribe(void)
return
_kk_client_subscribe
(
prpductType
,
prpductCode
);
return
_kk_client_subscribe
(
prpductType
,
prpductCode
);
}
}
static
int
_kk_utils_topic
(
_IN_
const
char
*
name
,
_IN_
char
*
product_key
,
_IN_
char
*
device_name
,
_OU_
char
**
topic
)
{
int
service_name_len
=
0
;
if
(
name
==
NULL
||
product_key
==
NULL
||
device_name
==
NULL
||
topic
==
NULL
||
*
topic
!=
NULL
)
{
return
-
1
;
}
service_name_len
=
strlen
(
KK_URI_SYS_PREFIX_EX
)
+
strlen
(
product_key
)
+
strlen
(
device_name
)
+
strlen
(
name
)
+
1
;
*
topic
=
malloc
(
service_name_len
);
if
(
*
topic
==
NULL
)
{
return
-
1
;
}
memset
(
*
topic
,
0
,
service_name_len
);
snprintf
(
*
topic
,
service_name_len
,
KK_URI_SYS_PREFIX_EX
,
product_key
,
device_name
);
if
(
name
!=
NULL
)
{
memcpy
(
*
topic
+
strlen
(
*
topic
),
name
,
strlen
(
name
));
}
return
0
;
}
char
*
KK_Make_Topic
(
cJSON
*
info
)
{
cJSON
*
type
,
*
product_type
,
*
device_name
,
*
root
;
kk_msg_type_t
msgtype
;
char
*
topic
=
NULL
;
root
=
cJSON_Parse
((
char
*
)
info
->
valuestring
);
type
=
cJSON_GetObjectItem
(
root
,
"msgtype"
);
if
(
type
==
NULL
){
goto
errorreturn
;
}
product_type
=
cJSON_GetObjectItem
(
root
,
"product_type"
);
if
(
product_type
==
NULL
){
goto
errorreturn
;
}
device_name
=
cJSON_GetObjectItem
(
root
,
"device_name"
);
if
(
device_name
==
NULL
){
goto
errorreturn
;
}
msgtype
=
atoi
(
type
->
valuestring
);
switch
(
msgtype
)
{
case
MSG_REGISTER
:
_kk_utils_topic
(
DM_URI_THING_SUB_REGISTER
,
product_type
->
valuestring
,
device_name
->
valuestring
,
&
topic
);
break
;
case
MSG_UNREGISTER
:
_kk_utils_topic
(
DM_URI_THING_SUB_UNREGISTER
,
product_type
->
valuestring
,
device_name
->
valuestring
,
&
topic
);
break
;
case
MSG_TOPOADD
:
_kk_utils_topic
(
DM_URI_THING_TOPO_ADD
,
product_type
->
valuestring
,
device_name
->
valuestring
,
&
topic
);
break
;
case
MSG_TOPODELETE
:
_kk_utils_topic
(
DM_URI_THING_TOPO_DELETE
,
product_type
->
valuestring
,
device_name
->
valuestring
,
&
topic
);
break
;
case
MSG_TOPOGET
:
_kk_utils_topic
(
DM_URI_THING_TOPO_GET
,
product_type
->
valuestring
,
device_name
->
valuestring
,
&
topic
);
break
;
case
MSG_LISTFOUND
:
_kk_utils_topic
(
DM_URI_THING_LIST_FOUND
,
product_type
->
valuestring
,
device_name
->
valuestring
,
&
topic
);
break
;
case
MSG_LOGIN
:
_kk_utils_topic
(
DM_URI_COMBINE_LOGIN
,
product_type
->
valuestring
,
device_name
->
valuestring
,
&
topic
);
break
;
case
MSG_LOGOUT
:
_kk_utils_topic
(
DM_URI_COMBINE_LOGOUT
,
product_type
->
valuestring
,
device_name
->
valuestring
,
&
topic
);
break
;
case
MSG_PROPERTYPOST
:
_kk_utils_topic
(
DM_URI_THING_EVENT_PROPERTY_POST
,
product_type
->
valuestring
,
device_name
->
valuestring
,
&
topic
);
break
;
case
MSG_EVENTPOST
:
{
cJSON
*
identify
;
char
*
service_name
=
NULL
;
int
service_name_len
=
0
;
identify
=
cJSON_GetObjectItem
(
root
,
"identifier"
);
if
(
identify
==
NULL
){
goto
errorreturn
;
}
service_name_len
=
strlen
(
DM_URI_THING_EVENT_POST
)
+
strlen
(
identify
->
valuestring
)
+
1
;
service_name
=
malloc
(
service_name_len
);
if
(
service_name
==
NULL
)
{
goto
errorreturn
;
}
snprintf
(
service_name
,
service_name_len
,
DM_URI_THING_EVENT_POST
,
identify
->
valuestring
);
_kk_utils_topic
(
service_name
,
product_type
->
valuestring
,
device_name
->
valuestring
,
&
topic
);
free
(
service_name
);
}
break
;
case
MSG_SERVICERESPONSE
:
{
cJSON
*
identify
;
char
*
service_name
=
NULL
;
int
service_name_len
=
0
;
identify
=
cJSON_GetObjectItem
(
root
,
"identifier"
);
if
(
identify
==
NULL
){
goto
errorreturn
;
}
service_name_len
=
strlen
(
DM_URI_THING_SERVICE_RESPONSE
)
+
strlen
(
identify
->
valuestring
)
+
1
;
service_name
=
malloc
(
service_name_len
);
if
(
service_name
==
NULL
)
{
goto
errorreturn
;
}
snprintf
(
service_name
,
service_name_len
,
DM_URI_THING_SERVICE_RESPONSE
,
identify
->
valuestring
);
_kk_utils_topic
(
service_name
,
product_type
->
valuestring
,
device_name
->
valuestring
,
&
topic
);
free
(
service_name
);
}
break
;
case
MSG_SETREPLY
:
_kk_utils_topic
(
DM_URI_THING_SERVICE_PROPERTY_SET_REPLY
,
product_type
->
valuestring
,
device_name
->
valuestring
,
&
topic
);
break
;
}
printf
(
"[%s][%d] TOPIC:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
topic
);
cJSON_Delete
(
root
);
return
topic
;
errorreturn:
cJSON_Delete
(
root
);
return
NULL
;
}
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