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
b951d6a6
Commit
b951d6a6
authored
Aug 06, 2020
by
黄振令
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://172.17.3.10:17001/chenweican/k-sdk
# Conflicts: # application/kcloud/kcloud_data_handle.c
parents
b049cedc
36737fa0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
112 additions
and
97 deletions
+112
-97
application/kcloud/kcloud_data_handle.c
application/kcloud/kcloud_data_handle.c
+112
-97
No files found.
application/kcloud/kcloud_data_handle.c
View file @
b951d6a6
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mqtt_api.h"
#include "com_api.h"
#include "cJSON.h"
static
char
*
_kk_data_create
(
const
char
*
topic
,
const
char
*
data
)
{
cJSON
*
root
;
char
*
out
;
root
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
root
,
"topic"
,
topic
);
cJSON_AddStringToObject
(
root
,
"payload"
,
data
);
out
=
cJSON_Print
(
root
);
cJSON_Delete
(
root
);
printf
(
"[%s][%d]%s
\n
"
,
__FUNCTION__
,
__LINE__
,
out
);
return
out
;
//free(out); /* Print to text, Delete the cJSON, print it, release the string. */
}
void
KK_Sendto_CloudData
(
void
*
data
,
int
len
)
{
cJSON
*
root
,
*
pTopic
,
*
pData
;
char
*
topic
=
NULL
;
char
*
payload
=
NULL
;
root
=
cJSON_Parse
((
char
*
)
data
);
if
(
root
==
NULL
)
{
return
;
}
pTopic
=
cJSON_GetObjectItem
(
root
,
"topic"
);
if
(
pTopic
==
NULL
)
{
return
;
}
pData
=
cJSON_GetObjectItem
(
root
,
"payload"
);
if
(
pData
==
NULL
)
{
return
;
}
printf
(
"[%s][%d] topic:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
pTopic
->
valuestring
);
printf
(
"[%s][%d] payload:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
pData
->
valuestring
);
KK_MQTT_SendMsg
(
pTopic
->
valuestring
,(
const
char
*
)
pData
->
valuestring
);
}
#define KK_FILTER_ADD_TOPIC "/thing/topo/add"
#define KK_FILTER_ADD_TOPIC_REPLY "/thing/topo/add_reply"
#define KK_FILTER_DELETE_TOPIC "/thing/topo/delete"
#define KK_FILTER_DELETE_TOPIC_REPLY "/thing/topo/delete_reply"
#define KK_FILTER_REGISTER_TOPIC "/thing/sub/register"
#define KK_FILTER_REGISTER_TOPIC_REPLY "/thing/sub/register_reply"
#define KK_FILTER_LOGIN_TOPIC "/thing/combine/login"
#define KK_FILTER_LOGIN_TOPIC_REPLY "/thing/combine/login_reply"
#define KK_FILTER_SET_TOPIC "/thing/service/property/set"
#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"
static
int
_check_invalid_topic
(
char
*
topic
)
{
if
(
strstr
(
topic
,
KK_FILTER_ADD_TOPIC
)
!=
NULL
&&
\
strstr
(
topic
,
KK_FILTER_ADD_TOPIC_REPLY
)
==
NULL
){
return
1
;
}
else
if
(
strstr
(
topic
,
KK_FILTER_DELETE_TOPIC
)
!=
NULL
&&
\
strstr
(
topic
,
KK_FILTER_DELETE_TOPIC_REPLY
)
==
NULL
){
return
1
;
}
else
if
(
strstr
(
topic
,
KK_FILTER_REGISTER_TOPIC
)
!=
NULL
&&
\
strstr
(
topic
,
KK_FILTER_REGISTER_TOPIC_REPLY
)
==
NULL
){
return
1
;
}
else
if
(
strstr
(
topic
,
KK_FILTER_LOGIN_TOPIC
)
!=
NULL
&&
\
strstr
(
topic
,
KK_FILTER_LOGIN_TOPIC_REPLY
)
==
NULL
){
return
1
;
}
else
if
(
strstr
(
topic
,
KK_FILTER_SET_TOPIC_REPLY
)
!=
NULL
){
return
1
;
}
else
if
(
strstr
(
topic
,
KK_FILTER_EVENT_POST_TOPIC
)
!=
NULL
&&
\
strstr
(
topic
,
KK_FILTER_LOGIN_TOPIC_REPLY
)
==
NULL
){
return
1
;
}
return
0
;
}
void
KK_Sendto_DevData
(
const
char
*
topic
,
const
char
*
data
)
{
if
(
_check_invalid_topic
(
topic
))
{
return
;
//ingore the message
}
char
*
send_data
=
_kk_data_create
(
topic
,
data
);
kk_ipc_send
(
IPC_APP2MID
,
send_data
,
strlen
(
send_data
)
+
1
);
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mqtt_api.h"
#include "com_api.h"
#include "cJSON.h"
#define KK_FILTER_ADD_TOPIC "/thing/topo/add"
#define KK_FILTER_ADD_TOPIC_REPLY "/thing/topo/add_reply"
#define KK_FILTER_DELETE_TOPIC "/thing/topo/delete"
#define KK_FILTER_DELETE_TOPIC_REPLY "/thing/topo/delete_reply"
#define KK_FILTER_REGISTER_TOPIC "/thing/sub/register"
#define KK_FILTER_REGISTER_TOPIC_REPLY "/thing/sub/register_reply"
#define KK_FILTER_LOGIN_TOPIC "/thing/combine/login"
#define KK_FILTER_LOGIN_TOPIC_REPLY "/thing/combine/login_reply"
#define KK_FILTER_SET_TOPIC "/thing/service/property/set"
#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"
int
_kk_sendto_cloud
(
cJSON
*
root
)
{
cJSON
*
pTopic
,
*
pData
;
char
*
topic
=
NULL
;
char
*
payload
=
NULL
;
pTopic
=
cJSON_GetObjectItem
(
root
,
"topic"
);
if
(
pTopic
==
NULL
){
return
;
}
pData
=
cJSON_GetObjectItem
(
root
,
"payload"
);
if
(
pData
==
NULL
){
return
;
}
printf
(
"[%s][%d] topic:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
pTopic
->
valuestring
);
printf
(
"[%s][%d] payload:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
pData
->
valuestring
);
KK_MQTT_SendMsg
(
pTopic
->
valuestring
,(
const
char
*
)
pData
->
valuestring
);
}
void
KK_Data_FromDev
(
void
*
str
,
int
len
)
{
cJSON
*
root
,
*
cmd
;
if
(
str
==
NULL
){
return
;
}
root
=
cJSON_Parse
((
char
*
)
str
);
if
(
root
==
NULL
){
return
;
}
cmd
=
cJSON_GetObjectItem
(
root
,
"cmd"
);
if
(
cmd
==
NULL
){
_kk_sendto_cloud
(
root
);
}
else
{
KK_Subdev_Subscribe
(
root
);
}
cJSON_Delete
(
root
);
free
(
root
);
}
static
int
_check_invalid_topic
(
const
char
*
topic
)
{
if
(
strstr
(
topic
,
KK_FILTER_ADD_TOPIC
)
!=
NULL
&&
\
strstr
(
topic
,
KK_FILTER_ADD_TOPIC_REPLY
)
==
NULL
){
return
1
;
}
else
if
(
strstr
(
topic
,
KK_FILTER_DELETE_TOPIC
)
!=
NULL
&&
\
strstr
(
topic
,
KK_FILTER_DELETE_TOPIC_REPLY
)
==
NULL
){
return
1
;
}
else
if
(
strstr
(
topic
,
KK_FILTER_REGISTER_TOPIC
)
!=
NULL
&&
\
strstr
(
topic
,
KK_FILTER_REGISTER_TOPIC_REPLY
)
==
NULL
){
return
1
;
}
else
if
(
strstr
(
topic
,
KK_FILTER_LOGIN_TOPIC
)
!=
NULL
&&
\
strstr
(
topic
,
KK_FILTER_LOGIN_TOPIC_REPLY
)
==
NULL
){
return
1
;
}
else
if
(
strstr
(
topic
,
KK_FILTER_SET_TOPIC_REPLY
)
!=
NULL
){
return
1
;
}
else
if
(
strstr
(
topic
,
KK_FILTER_EVENT_POST_TOPIC
)
!=
NULL
&&
\
strstr
(
topic
,
KK_FILTER_LOGIN_TOPIC_REPLY
)
==
NULL
){
return
1
;
}
return
0
;
}
static
char
*
_kk_data_create
(
const
char
*
topic
,
const
char
*
data
)
{
cJSON
*
root
;
char
*
out
;
root
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
root
,
"topic"
,
topic
);
cJSON_AddStringToObject
(
root
,
"payload"
,
data
);
out
=
cJSON_Print
(
root
);
cJSON_Delete
(
root
);
printf
(
"[%s][%d]%s
\n
"
,
__FUNCTION__
,
__LINE__
,
out
);
return
out
;
//free(out); /* Print to text, Delete the cJSON, print it, release the string. */
}
void
KK_Sendto_DevData
(
const
char
*
topic
,
const
char
*
data
)
{
if
(
_check_invalid_topic
(
topic
))
{
return
;
//ingore the message
}
char
*
send_data
=
_kk_data_create
(
topic
,
data
);
kk_ipc_send
(
IPC_APP2MID
,
send_data
,
strlen
(
send_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