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
de8966fc
Commit
de8966fc
authored
Aug 07, 2020
by
黄振令
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】1. palt和mid增加queue 处理;2. 发送plat数据去掉topic,增加mac字段
【提交人】黄振令
parent
0ae047b0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
199 additions
and
5 deletions
+199
-5
midware/midware/dm/kk_dm_queue.c
midware/midware/dm/kk_dm_queue.c
+109
-0
midware/midware/dm/kk_dm_queue.h
midware/midware/dm/kk_dm_queue.h
+2
-0
midware/midware/dm/kk_linkkit.c
midware/midware/dm/kk_linkkit.c
+2
-0
midware/midware/midware.c
midware/midware/midware.c
+86
-5
No files found.
midware/midware/dm/kk_dm_queue.c
View file @
de8966fc
...
...
@@ -23,6 +23,15 @@ static void _dm_queue_lock(void)
}
}
static
void
_dm_queue_lock2
(
void
)
{
dm_queue_t
*
ctx
=
_dm_queue_get_ctx
();
if
(
ctx
->
mutex2
)
{
HAL_MutexLock
(
ctx
->
mutex2
);
}
}
static
void
_dm_queue_unlock
(
void
)
{
dm_queue_t
*
ctx
=
_dm_queue_get_ctx
();
...
...
@@ -30,6 +39,14 @@ static void _dm_queue_unlock(void)
HAL_MutexUnlock
(
ctx
->
mutex
);
}
}
static
void
_dm_queue_unlock2
(
void
)
{
dm_queue_t
*
ctx
=
_dm_queue_get_ctx
();
if
(
ctx
->
mutex2
)
{
HAL_MutexUnlock
(
ctx
->
mutex2
);
}
}
int
dm_queue_init
(
int
max_size
)
{
...
...
@@ -43,9 +60,17 @@ int dm_queue_init(int max_size)
return
INVALID_PARAMETER
;
}
/* Create Mutex */
ctx
->
mutex2
=
HAL_MutexCreate
();
if
(
ctx
->
mutex2
==
NULL
)
{
return
INVALID_PARAMETER
;
}
/* Init List */
ctx
->
msg_list
.
max_size
=
max_size
;
INIT_LIST_HEAD
(
&
ctx
->
msg_list
.
message_list
);
ctx
->
msg_list2
.
max_size
=
max_size
;
INIT_LIST_HEAD
(
&
ctx
->
msg_list2
.
message_list
);
return
SUCCESS_RETURN
;
}
...
...
@@ -61,6 +86,10 @@ void dm_queue_deinit(void)
HAL_MutexDestroy
(
ctx
->
mutex
);
}
if
(
ctx
->
mutex2
)
{
HAL_MutexDestroy
(
ctx
->
mutex2
);
}
list_for_each_entry_safe
(
del_node
,
next_node
,
&
ctx
->
msg_list
.
message_list
,
linked_list
,
dm_queue_msg_node_t
)
{
/* Free Message */
del_msg
=
(
dm_queue_msg_t
*
)
del_node
->
data
;
...
...
@@ -74,6 +103,25 @@ void dm_queue_deinit(void)
list_del
(
&
del_node
->
linked_list
);
free
(
del_node
);
}
del_node
=
NULL
;
next_node
=
NULL
;
del_msg
=
NULL
;
list_for_each_entry_safe
(
del_node
,
next_node
,
&
ctx
->
msg_list2
.
message_list
,
linked_list
,
dm_queue_msg_node_t
)
{
/* Free Message */
del_msg
=
(
dm_queue_msg_t
*
)
del_node
->
data
;
if
(
del_msg
->
data
)
{
free
(
del_msg
->
data
);
}
free
(
del_msg
);
del_msg
=
NULL
;
/* Free Node */
list_del
(
&
del_node
->
linked_list
);
free
(
del_node
);
}
}
int
dm_queue_msg_insert
(
void
*
data
)
...
...
@@ -136,3 +184,64 @@ int dm_queue_msg_next(void **data)
return
SUCCESS_RETURN
;
}
int
dm_queue_msg_insert2
(
void
*
data
)
{
dm_queue_t
*
ctx
=
_dm_queue_get_ctx
();
dm_queue_msg_node_t
*
node
=
NULL
;
if
(
data
==
NULL
)
{
return
INVALID_PARAMETER
;
}
_dm_queue_lock2
();
printf
(
"dm msg list size: %d, max size: %d"
,
ctx
->
msg_list2
.
size
,
ctx
->
msg_list2
.
max_size
);
if
(
ctx
->
msg_list2
.
size
>=
ctx
->
msg_list2
.
max_size
)
{
printf
(
"dm queue list full"
);
_dm_queue_unlock2
();
return
FAIL_RETURN
;
}
node
=
malloc
(
sizeof
(
dm_queue_msg_node_t
));
if
(
node
==
NULL
)
{
_dm_queue_unlock2
();
return
MEMORY_NOT_ENOUGH
;
}
memset
(
node
,
0
,
sizeof
(
dm_queue_msg_node_t
));
node
->
data
=
data
;
INIT_LIST_HEAD
(
&
node
->
linked_list
);
ctx
->
msg_list2
.
size
++
;
list_add_tail
(
&
node
->
linked_list
,
&
ctx
->
msg_list2
.
message_list
);
_dm_queue_unlock2
();
return
SUCCESS_RETURN
;
}
int
dm_queue_msg_next2
(
void
**
data
)
{
dm_queue_t
*
ctx
=
_dm_queue_get_ctx
();
dm_queue_msg_node_t
*
node
=
NULL
;
if
(
data
==
NULL
||
*
data
!=
NULL
)
{
return
INVALID_PARAMETER
;
}
_dm_queue_lock2
();
if
(
list_empty
(
&
ctx
->
msg_list2
.
message_list
))
{
_dm_queue_unlock2
();
return
FAIL_RETURN
;
}
node
=
list_first_entry
(
&
ctx
->
msg_list2
.
message_list
,
dm_queue_msg_node_t
,
linked_list
);
list_del
(
&
node
->
linked_list
);
ctx
->
msg_list2
.
size
--
;
*
data
=
node
->
data
;
free
(
node
);
_dm_queue_unlock2
();
return
SUCCESS_RETURN
;
}
midware/midware/dm/kk_dm_queue.h
View file @
de8966fc
...
...
@@ -28,7 +28,9 @@ typedef struct {
typedef
struct
{
void
*
mutex
;
void
*
mutex2
;
dm_queue_msg_list_t
msg_list
;
dm_queue_msg_list_t
msg_list2
;
}
dm_queue_t
;
int
dm_queue_init
(
int
max_size
);
...
...
midware/midware/dm/kk_linkkit.c
View file @
de8966fc
...
...
@@ -295,6 +295,8 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
}
}
cJSON_Delete
(
json
);
}
#if 0
...
...
midware/midware/midware.c
View file @
de8966fc
...
...
@@ -14,6 +14,7 @@
#include "cJSON.h"
#include "kk_product.h"
#include "kk_tsl_common.h"
#include "kk_dm_api.h"
...
...
@@ -32,7 +33,7 @@ void mid_cb(void* data, int len){
payload
=
cJSON_GetObjectItem
(
json
,
"payload"
);
printf
(
"mid_cb topic: [%s] ,payload= %s
\n
"
,
topic
->
valuestring
,
payload
->
valuestring
);
if
(
strcmp
(
payload
->
valuestring
,
"addsub"
)
==
0
){
kk_mid_subdev_add
(
"a1OYuSallan"
,
"allanWno8yDdsjCX15iq"
,
"
"
,
""
);
//kk_mid_subdev_add("a1OYuSallan","allanWno8yDdsjCX15iq
","");
}
else
{
void
*
buf
=
malloc
(
len
);
memcpy
(
buf
,
data
,
len
);
...
...
@@ -44,19 +45,99 @@ void mid_cb(void* data, int len){
//kk_tsl_service_property_set(topic->valuestring, payload->valuestring, strlen(payload->valuestring), NULL);
}
cJSON
*
jsonplay
=
cJSON_Parse
(
payload
->
valuestring
);
cJSON_AddStringToObject
(
jsonplay
,
"mac"
,
"aabbccddee11"
);
void
*
out
=
cJSON_Print
(
jsonplay
);
kk_ipc_send
(
IPC_MID2PLAT
,
out
,
strlen
(
out
));
free
(
out
);
cJSON_Delete
(
jsonplay
);
cJSON_Delete
(
json
);
}
kk_ipc_send
(
IPC_MID2PLAT
,
data
,
len
);
}
}
void
mid2p_cb
(
void
*
data
,
int
len
){
if
(
data
!=
NULL
){
printf
(
"mid2p_cb: %s RECEIVED
\r\n
"
,
data
);
kk_ipc_send
(
IPC_MID2APP
,
data
,
len
);
printf
(
"mid2plat_cb: %s RECEIVED
\r\n
"
,
data
);
void
*
buf
=
malloc
(
len
);
memcpy
(
buf
,
data
,
len
);
int
res
=
dm_queue_msg_insert2
((
void
*
)
buf
);
if
(
res
!=
SUCCESS_RETURN
)
{
free
(
buf
);
return
;
}
//kk_ipc_send(IPC_MID2APP, data, len);
}
}
void
kk_platMsg_handle
(
void
*
data
){
char
*
out
;
int
res
=
0
;
cJSON
*
json
,
*
method
,
*
params
;
json
=
cJSON_Parse
(
data
);
if
(
!
json
)
{
printf
(
"Error before: [%s]
\n
"
,
"cJSON_Parse"
);
}
else
{
method
=
cJSON_GetObjectItem
(
json
,
"method"
);
if
(
method
!=
NULL
&&
strcmp
(
method
->
valuestring
,
"thing.topo.add"
)
==
0
){
cJSON
*
jsonPay
,
*
proType
,
*
proCode
,
*
mac
;
params
=
cJSON_GetObjectItem
(
json
,
"params"
);
jsonPay
=
cJSON_Parse
(
params
->
valuestring
);
if
(
!
jsonPay
)
{
printf
(
"Error before: [%s]
\n
"
,
"cJSON_Parse"
);
}
else
{
proType
=
cJSON_GetObjectItem
(
jsonPay
,
"productType"
);
proCode
=
cJSON_GetObjectItem
(
jsonPay
,
"productCode"
);
mac
=
cJSON_GetObjectItem
(
jsonPay
,
"mac"
);
printf
(
"productType productCode : [%s][%s]
\n
"
,
proType
,
proCode
);
kk_set_tsl_by_productKey
(
proCode
->
valuestring
,
"model.json"
);
kk_mid_subdev_add
(
proType
->
valuestring
,
proCode
->
valuestring
,
""
,
mac
->
valuestring
);
cJSON_Delete
(
jsonPay
);
}
}
else
if
(
method
!=
NULL
&&
strcmp
(
method
->
valuestring
,
"thing.event.property.post"
)
==
0
){
//kk_tsl_service_property_set(topic->valuestring, data, strlen(data), NULL);
}
else
{
printf
(
"kk_platMsg_handle data: [%s]
\n
"
,
data
);
//kk_tsl_service_property_set(topic->valuestring, payload->valuestring, strlen(payload->valuestring), NULL);
}
cJSON_Delete
(
json
);
}
}
void
kk_platMsg_dispatch
(
void
)
{
int
count
=
0
;
void
*
data
=
NULL
;
while
(
CONFIG_DISPATCH_QUEUE_MAXLEN
==
0
||
count
++
<
CONFIG_DISPATCH_QUEUE_MAXLEN
)
{
if
(
dm_queue_msg_next2
(
&
data
)
==
SUCCESS_RETURN
)
{
//dm_queue_msg_t *msg = (dm_queue_msg_t *)data;
printf
(
"kk_handle_platMsg_dispatch get call
\n
"
);
if
(
kk_platMsg_handle
)
{
kk_platMsg_handle
(
data
);
}
free
(
data
);
data
=
NULL
;
}
else
{
break
;
}
}
}
#define MYPORT 5555
...
...
@@ -191,7 +272,7 @@ int main(const int argc, const char **argv)
ct
=
1
;
kk_set_tsl_by_productKey
(
"a1OYuSallan"
,
"model.json"
);
kk_mid_subdev_add
(
"a1OYuSallan"
,
"allanWno8yDdsjCX15iq"
,
""
,
""
);
kk_mid_subdev_add
(
"a1OYuSallan"
,
"allanWno8yDdsjCX15iq"
,
""
,
"
aabbccddeeff1122
"
);
}
/*memset(buf, 0, 100);
...
...
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