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
545bd2f3
Commit
545bd2f3
authored
Nov 17, 2020
by
chen.weican
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】1,增加场景设置灯控面板对所有灯控制的支持;2,支持网关在同IP情况下与主机的消息收发支持
parent
21b41429
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
192 additions
and
18 deletions
+192
-18
midware/midware/dm/kk_sub_db.c
midware/midware/dm/kk_sub_db.c
+50
-12
midware/midware/midware.c
midware/midware/midware.c
+142
-6
No files found.
midware/midware/dm/kk_sub_db.c
View file @
545bd2f3
...
...
@@ -570,13 +570,16 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *scen
dm_mgr_dev_node_t
*
node
=
NULL
;
kk_subDb_ctx_t
*
ctx
=
_kk_subDb_get_ctx
();
const
char
*
searchCmd
=
"select * from SubDeviceInfo WHERE productType= '%s'"
;
int
idx
=
0
;
int
gw_support_scene
=
0
;
kk_tsl_data_t
*
property
=
NULL
;
if
(
productType
==
NULL
){
ERROR_PRINT
(
"ERROR [%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
return
INVALID_PARAMETER
;
}
sqlCmd
=
sqlite3_mprintf
(
searchCmd
,
productType
);
sqlCmd
=
sqlite3_mprintf
(
searchCmd
,
productType
);
//switch jsut for test
sqlite3_prepare_v2
(
ctx
->
pDb
,
sqlCmd
,
strlen
(
sqlCmd
),
&
stmt
,
NULL
);
//INFO_PRINT("total_column = %d\n", sqlite3_column_count(stmt));
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
){
...
...
@@ -586,22 +589,57 @@ int kk_subDev_set_action_by_productType(const char *productType,const char *scen
continue
;
}
if
(
kk_subDev_check_scene_support
(
node
->
fatherDeviceCode
)
==
1
){
gw_support_scene
=
1
;
}
else
{
gw_support_scene
=
0
;
}
if
(
!
strcmp
(
productType
,
"switch"
)){
for
(
idx
=
0
;
idx
<
node
->
dev_shadow
->
property_number
;
idx
++
){
property
=
(
kk_tsl_data_t
*
)(
node
->
dev_shadow
->
properties
+
idx
);
if
(
property
==
NULL
){
continue
;
}
if
(
strstr
(
property
->
identifier
,
"PowerSwitch"
)
!=
NULL
){
if
(
gw_support_scene
){
kk_scene_action_detail_t
info
=
{
0
};
memcpy
(
info
.
deviceCode
,
node
->
deviceCode
,
strlen
(
node
->
deviceCode
));
memcpy
(
info
.
propertyName
,
propertyName
,
strlen
(
propertyName
));
memcpy
(
info
.
propertyName
,
property
->
identifier
,
strlen
(
property
->
identifier
));
memcpy
(
info
.
propertyValue
,
propertyValue
,
strlen
(
propertyValue
));
info
.
epNum
=
1
;
info
.
delay
=
0
;
kk_scene_action_add
(
node
->
fatherDeviceCode
,
sceneId
,
info
);
res
=
kk_scene_insert_scene_action
(
type
,
node
->
deviceCode
,
info
.
epNum
,
propertyName
,
propertyValue
,
info
.
delay
,
sceneId
,
node
->
fatherDeviceCode
);
}
res
=
kk_scene_insert_scene_action
(
type
,
node
->
deviceCode
,
1
,
property
->
identifier
,
propertyValue
,
0
,
sceneId
,
node
->
fatherDeviceCode
);
if
(
res
!=
SUCCESS_RETURN
){
INFO_PRINT
(
"kk_subDev_set_action_by_productType fail!!!
\n
"
);
//return res;
continue
;
}
}
}
}
else
{
if
(
gw_support_scene
){
kk_scene_action_detail_t
info
=
{
0
};
memcpy
(
info
.
deviceCode
,
node
->
deviceCode
,
strlen
(
node
->
deviceCode
));
memcpy
(
info
.
propertyName
,
propertyName
,
strlen
(
propertyName
));
memcpy
(
info
.
propertyValue
,
propertyValue
,
strlen
(
propertyValue
));
info
.
epNum
=
1
;
info
.
delay
=
0
;
kk_scene_action_add
(
node
->
fatherDeviceCode
,
sceneId
,
info
);
}
res
=
kk_scene_insert_scene_action
(
type
,
node
->
deviceCode
,
1
,
propertyName
,
propertyValue
,
0
,
sceneId
,
node
->
fatherDeviceCode
);
if
(
res
!=
SUCCESS_RETURN
){
INFO_PRINT
(
"kk_subDev_set_action_by_productType fail!!!
\n
"
);
//return res;
continue
;
}
}
}
sqlite3_finalize
(
stmt
);
sqlite3_free
(
sqlCmd
);
...
...
midware/midware/midware.c
View file @
545bd2f3
/************************************************************
*版权所有 (C)2020,公司(或个人)名称
*
*文件名称: midware.c
*内容摘要: 数据中转中心,上对云端,下对网关,承上启下
*其他说明:
*当前版本:
*************************************************************/
#include<stdio.h>
#include"com_api.h"
#include <sys/types.h>
...
...
@@ -44,6 +55,13 @@ char * g_filerToPlatTable[] =
{
KK_THING_SERVICE_DELETESCENC
},
{
KK_THING_SERVICE_NEGATIVE
},
};
/************************************************************
*功能描述:过滤不需要下发给网关的消息
*输入参数:msgtype:消息类型
*输出参数:无
*返 回 值:1:过滤;0:不过滤
*其他说明:
*************************************************************/
static
int
_kk_filter_to_plat
(
const
char
*
msgtype
)
{
int
i
=
0
,
num
=
0
;
...
...
@@ -59,6 +77,15 @@ static int _kk_filter_to_plat(const char* msgtype)
return
0
;
}
/************************************************************
*功能描述:向网关发送信息
*输入参数:data:消息内容
len:消息长度
chalMark:消息通道,一般是网关MAC
*输出参数:无
*返 回 值: 无
*其他说明:
*************************************************************/
void
kk_sendData2gw
(
void
*
data
,
int
len
,
char
*
chalMark
){
if
(
chalMark
==
NULL
||
strlen
(
chalMark
)
==
0
){
ERROR_PRINT
(
" chalMark is null"
);
...
...
@@ -74,6 +101,15 @@ void kk_sendData2gw(void* data, int len, char* chalMark){
}
}
/************************************************************
*功能描述:属性参数校验
*输入参数:payload:消息内容
deviceCode:设备devieCode
*输出参数:无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
static
int
kk_property_set_data_check
(
cJSON
*
payload
,
const
char
*
deviceCode
){
cJSON
*
params
=
NULL
;
dm_mgr_dev_node_t
*
node
=
NULL
;
...
...
@@ -181,6 +217,15 @@ static int kk_property_set_data_check(cJSON * payload,const char *deviceCode){
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述:nanomsg数据回调,app to mid
*输入参数:data:从app 层发来的数据
len: 数据长度
*输出参数:无
*返 回 值: 无
*其他说明:
*************************************************************/
void
mid_cb
(
void
*
data
,
int
len
){
if
(
data
!=
NULL
){
cJSON
*
payload
;
...
...
@@ -258,6 +303,16 @@ void mid_cb(void* data, int len){
}
}
/************************************************************
*功能描述:nanomsg数据回调,从gw to mid
*输入参数:data:从gw 层发来的数据
len: 数据长度
chalMark:网关通道,一般用mac
*输出参数:无
*返 回 值: 无
*其他说明:
*************************************************************/
void
mid2p_cb
(
void
*
data
,
int
len
,
char
*
chalMark
){
if
(
data
!=
NULL
){
//printf("mid2plat_cb: %s RECEIVED \r\n", data);
...
...
@@ -292,13 +347,29 @@ void mid2p_cb(void* data, int len, char* chalMark){
}
}
/************************************************************
*功能描述:nanomsg数据回调,从gw to mid
*输入参数:data:从gw 层发来的数据
len: 数据长度
chalMark:网关通道,一般用mac
*输出参数:无
*返 回 值: 无
*其他说明:
*************************************************************/
void
gw2mid_cb
(
void
*
data
,
int
len
,
char
*
chalMark
){
if
(
data
!=
NULL
){
printf
(
"gw2mid_cb chalMark=%s, data: %s [%d]RECEIVED
\r\n
"
,
chalMark
,
data
,
len
);
mid2p_cb
(
data
,
len
,
chalMark
);
}
}
/************************************************************
*功能描述:midware收到gw数据的具体处理
*输入参数:data:从gw 层发来的数据
chalMark:网关通道,一般用mac
*输出参数:无
*返 回 值: 无
*其他说明:
*************************************************************/
void
kk_platMsg_handle
(
void
*
data
,
char
*
chalMark
){
char
*
out
;
...
...
@@ -533,6 +604,13 @@ void kk_platMsg_handle(void* data, char* chalMark){
}
}
/************************************************************
*功能描述:从gw接收消息任务
*输入参数:无
*输出参数:无
*返 回 值: 无
*其他说明:
*************************************************************/
void
kk_platMsg_dispatch
(
void
)
{
int
count
=
0
;
...
...
@@ -586,6 +664,14 @@ static mid_ctx_t *kk_mid_get_ctx(void)
}
extern
void
IOT_Linkkit_Yield
(
int
timeout_ms
);
/************************************************************
*功能描述:从app接收消息任务
*输入参数:无
*输出参数:无
*返 回 值: 无
*其他说明:
*************************************************************/
void
*
mid_dispatch_yield
(
void
*
args
)
{
mid_ctx_t
*
mid_ctx
=
kk_mid_get_ctx
();
...
...
@@ -596,7 +682,13 @@ void *mid_dispatch_yield(void *args)
return
NULL
;
}
/************************************************************
*功能描述:接收OTA消息任务
*输入参数:无
*输出参数:无
*返 回 值: 无
*其他说明:
*************************************************************/
void
*
ota_dispatch_yield
(
void
*
args
)
{
mid_ctx_t
*
mid_ctx
=
kk_mid_get_ctx
();
...
...
@@ -612,7 +704,13 @@ void *ota_dispatch_yield(void *args)
#define UDP_LAN_PORT 25556
#define UDP_LAN_PORT_HOST 25555
#define test_
/************************************************************
*功能描述:网关发现server
*输入参数:args:传入参数
*输出参数:无
*返 回 值: 无
*其他说明:
*************************************************************/
void
*
udp_dispatch_yield
(
void
*
args
){
...
...
@@ -686,7 +784,6 @@ void *udp_dispatch_yield(void *args){
while
(
1
)
{
//从广播地址接受消息
memset
(
szDec
,
0
,
sizeof
(
szDec
));
int
size
=
recvfrom
(
sock
,
szDec
,
sizeof
(
szDec
),
0
,
(
struct
sockaddr
*
)
&
from
,(
socklen_t
*
)
&
len
);
...
...
@@ -709,6 +806,7 @@ void *udp_dispatch_yield(void *args){
int
itemConnetLen
=
0
;
char
gwDevCode
[
DEVICE_CODE_LEN
]
=
{
0
};
char
proto
[
10
]
=
{
0
};
char
portStr
[
10
]
=
{
0
};
tmp
=
strstr
(
getConnet
,
"deviceCode="
);
...
...
@@ -735,7 +833,19 @@ void *udp_dispatch_yield(void *args){
memcpy
(
proto
,
tmp
+
itemLen
,
itemConnetLen
);
}
DEBUG_PRINT
(
"gwDevCode =%s proto=%s
\n
"
,
gwDevCode
,
proto
);
tmp
=
strstr
(
getConnet
,
"port="
);
itemLen
=
strlen
(
"port="
);
if
(
tmp
!=
NULL
){
endIdx
=
strstr
(
tmp
,
";"
);
if
(
endIdx
==
NULL
){
itemConnetLen
=
strlen
(
tmp
)
-
itemLen
;
}
else
{
itemConnetLen
=
endIdx
-
tmp
-
itemLen
;
}
memcpy
(
portStr
,
tmp
+
itemLen
,
itemConnetLen
);
}
DEBUG_PRINT
(
"gwDevCode =%s proto=%s portStr=%s
\n
"
,
gwDevCode
,
proto
,
portStr
);
if
(
strcmp
(
proto
,
"tcp"
)
==
0
){
//
...
...
@@ -754,7 +864,11 @@ void *udp_dispatch_yield(void *args){
//sendto(sock, szOut, strlen(szOut), 0, (struct sockaddr*)&from,len);
addrto_host
.
sin_addr
.
s_addr
=
inet_addr
(
inet_ntoa
(
from
.
sin_addr
));
if
(
strlen
(
portStr
)
>
0
){
addrto_host
.
sin_port
=
htons
(
atoi
(
portStr
));
}
else
{
addrto_host
.
sin_port
=
htons
(
UDP_LAN_PORT_HOST
);
}
//addrto_host.sin_port = from.sin_port;
//if(strcmp(host_ip,inet_ntoa(from.sin_addr)) == 0)
//{
...
...
@@ -774,6 +888,13 @@ void *udp_dispatch_yield(void *args){
close
(
sock
);
close
(
sock_host
);
}
/************************************************************
*功能描述:主机IP后台检测任务,如IP有变化,上报消息给云端
*输入参数:无
*输出参数:无
*返 回 值: 无
*其他说明:
*************************************************************/
void
*
ccu_property_monitor
(
void
*
args
)
{
mid_ctx_t
*
mid_ctx
=
kk_mid_get_ctx
();
...
...
@@ -824,6 +945,13 @@ void *ccu_property_monitor(void *args)
sqlite3
*
g_kk_pDb
;
#define KK_DB_FILE "/usr/kk/kk_database.db"
/************************************************************
*功能描述:主机数据库句柄创建
*输入参数:无
*输出参数:无
*返 回 值: 0:成功;其他:失败
*其他说明:
*************************************************************/
int
kk_sqlite_init
(
void
)
{
if
(
sqlite3_open_v2
(
KK_DB_FILE
,
&
g_kk_pDb
,
SQLITE_OPEN_READWRITE
|
SQLITE_OPEN_CREATE
|
SQLITE_OPEN_FULLMUTEX
,
NULL
)
!=
SQLITE_OK
)
...
...
@@ -833,6 +961,14 @@ int kk_sqlite_init(void)
}
return
SUCCESS_RETURN
;
}
/************************************************************
*功能描述:midware 主任务
*输入参数:argc:参数个数
argv:参数内容
*输出参数:无
*返 回 值: 无
*其他说明:
*************************************************************/
int
main
(
const
int
argc
,
const
char
**
argv
)
{
...
...
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