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
5af6ad5a
Commit
5af6ad5a
authored
Sep 03, 2021
by
尹佳钦
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【20210903】 局域网SIGPIPE问题
parent
f5d4b33b
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
255 additions
and
54 deletions
+255
-54
application/klansdk/kk_data_handle.c
application/klansdk/kk_data_handle.c
+21
-2
application/klansdk/kk_data_mng.c
application/klansdk/kk_data_mng.c
+4
-20
application/klansdk/kk_lan_ctrl.c
application/klansdk/kk_lan_ctrl.c
+109
-7
application/klansdk/kk_lan_main.c
application/klansdk/kk_lan_main.c
+22
-0
application/klansdk/kk_lan_sync.c
application/klansdk/kk_lan_sync.c
+18
-2
application/klansdk/kk_lan_sync.h
application/klansdk/kk_lan_sync.h
+1
-1
application/klansdk/kk_login_handle.c
application/klansdk/kk_login_handle.c
+32
-5
application/klansdk/kk_login_handle.h
application/klansdk/kk_login_handle.h
+4
-0
application/klansdk/kk_oldccu_msg.c
application/klansdk/kk_oldccu_msg.c
+10
-17
application/klansdk/kk_opcode.h
application/klansdk/kk_opcode.h
+3
-0
midware/midware/dm/kk_dm_msg.c
midware/midware/dm/kk_dm_msg.c
+22
-0
midware/midware/dm/kk_dm_msg.h
midware/midware/dm/kk_dm_msg.h
+6
-0
midware/midware/dm/kk_linkkit.c
midware/midware/dm/kk_linkkit.c
+3
-0
No files found.
application/klansdk/kk_data_handle.c
View file @
5af6ad5a
...
@@ -119,6 +119,21 @@ void kk_handle_sync_info(void)
...
@@ -119,6 +119,21 @@ void kk_handle_sync_info(void)
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
);
free
(
send_data
);
}
}
void
kk_handle_sync_push_info
(
void
)
{
char
*
send_data
=
NULL
;
send_data
=
_kk_data_create
(
SYNCPUSH_MSG_TYPE
,
"*"
,
"*"
,
"*"
);
if
(
send_data
==
NULL
){
return
;
}
debug_log
(
LOG_INFO_LEVEL
,
"[sync] send.
\n
"
);
kk_ipc_send
(
IPC_APP2MID
,
send_data
,
strlen
(
send_data
)
+
1
);
free
(
send_data
);
}
void
kk_handle_get_history_info
(
void
)
void
kk_handle_get_history_info
(
void
)
{
{
char
*
send_data
=
NULL
;
char
*
send_data
=
NULL
;
...
@@ -744,7 +759,7 @@ void KK_Data_FromMid(void* str,int len)
...
@@ -744,7 +759,7 @@ void KK_Data_FromMid(void* str,int len)
cJSON
*
info
=
NULL
,
*
payload
=
NULL
;
cJSON
*
info
=
NULL
,
*
payload
=
NULL
;
cJSON
*
msgtype
=
NULL
,
*
deviceCode
=
NULL
,
*
productCode
=
NULL
;
cJSON
*
msgtype
=
NULL
,
*
deviceCode
=
NULL
,
*
productCode
=
NULL
;
debug_log
(
LOG_FOCUS_LEVEL
,
"[midware->lan] len=%d,data=%s
\n
"
,
len
,
str
);
debug_log
(
LOG_FOCUS_LEVEL
,
"[midware->lan] len=%d,data=%s
\n
"
,
len
,
(
char
*
)
str
);
if
((
json
=
cJSON_Parse
(
str
))
==
NULL
)
{
if
((
json
=
cJSON_Parse
(
str
))
==
NULL
)
{
return
;
return
;
...
@@ -772,7 +787,11 @@ void KK_Data_FromMid(void* str,int len)
...
@@ -772,7 +787,11 @@ void KK_Data_FromMid(void* str,int len)
if
(
strstr
(
msgtype
->
valuestring
,
SYNC_MSG_TYPE_REPLY
)
!=
NULL
){
if
(
strstr
(
msgtype
->
valuestring
,
SYNC_MSG_TYPE_REPLY
)
!=
NULL
){
kk_parse_syncinfo
(
payload
);
kk_parse_syncinfo
(
payload
);
kk_create_syncinfo_to_sdk
(
payload
);
kk_create_syncinfo_to_sdk
(
payload
,
0
);
kk_vp_syncinfo_handle
(
payload
);
}
else
if
(
strstr
(
msgtype
->
valuestring
,
SYNCPUSH_MSG_TYPE_REPLY
)
!=
NULL
){
kk_parse_syncinfo
(
payload
);
kk_create_syncinfo_to_sdk
(
payload
,
1
);
kk_vp_syncinfo_handle
(
payload
);
kk_vp_syncinfo_handle
(
payload
);
}
}
else
if
(
strstr
(
msgtype
->
valuestring
,
"/thing/event/property/post"
)
!=
NULL
){
else
if
(
strstr
(
msgtype
->
valuestring
,
"/thing/event/property/post"
)
!=
NULL
){
...
...
application/klansdk/kk_data_mng.c
View file @
5af6ad5a
...
@@ -152,25 +152,13 @@ static kk_map_dev_node_t *kk_map_dev_node_create(const char *deviceCode,const ch
...
@@ -152,25 +152,13 @@ static kk_map_dev_node_t *kk_map_dev_node_create(const char *deviceCode,const ch
node
->
syn_opcode
=
(
char
*
)
malloc
(
strlen
(
syn_opcode
->
valuestring
)
+
1
);
node
->
syn_opcode
=
(
char
*
)
malloc
(
strlen
(
syn_opcode
->
valuestring
)
+
1
);
memset
(
node
->
syn_opcode
,
0
,
strlen
(
syn_opcode
->
valuestring
)
+
1
);
memset
(
node
->
syn_opcode
,
0
,
strlen
(
syn_opcode
->
valuestring
)
+
1
);
memcpy
(
node
->
syn_opcode
,
syn_opcode
->
valuestring
,
strlen
(
syn_opcode
->
valuestring
));
memcpy
(
node
->
syn_opcode
,
syn_opcode
->
valuestring
,
strlen
(
syn_opcode
->
valuestring
));
if
(
node
->
syn_opcode
!=
NULL
){
debug_log
(
LOG_CRITICAL_LEVEL
,
"111---->devNode->syn_opcode=%s[%d].
\n
"
,
node
->
syn_opcode
,
strlen
(
node
->
syn_opcode
));
}
else
{
debug_log
(
LOG_CRITICAL_LEVEL
,
"111---->devNode->syn_opcode.
\n
"
);
}
}
}
if
(
node
->
syn_opcode
!=
NULL
){
debug_log
(
LOG_CRITICAL_LEVEL
,
"111---->devNode->syn_opcode=%s[%d].
\n
"
,
node
->
syn_opcode
,
strlen
(
node
->
syn_opcode
));
}
else
{
debug_log
(
LOG_CRITICAL_LEVEL
,
"111---->devNode->syn_opcode.
\n
"
);
}
free
(
buf
);
free
(
buf
);
if
(
node
->
syn_opcode
!=
NULL
){
debug_log
(
LOG_CRITICAL_LEVEL
,
"111---->devNode->syn_opcode=%s[%d].
\n
"
,
node
->
syn_opcode
,
strlen
(
node
->
syn_opcode
));
}
else
{
debug_log
(
LOG_CRITICAL_LEVEL
,
"111---->devNode->syn_opcode.
\n
"
);
}
return
node
;
return
node
;
err:
err:
...
@@ -506,11 +494,7 @@ kk_map_dev_node_t *kk_map_dev_node_add(const char *deviceCode,const char *produc
...
@@ -506,11 +494,7 @@ kk_map_dev_node_t *kk_map_dev_node_add(const char *deviceCode,const char *produc
_kk_map_dev_mutex_lock
();
_kk_map_dev_mutex_lock
();
if
((
buf
=
kk_open_lan_cfg_file
(
productCode
))
!=
NULL
){
if
((
buf
=
kk_open_lan_cfg_file
(
productCode
))
!=
NULL
){
node
=
kk_map_dev_node_create
(
deviceCode
,
productCode
,
gwdeviceCode
,
onlineStatus
,
buf
);
node
=
kk_map_dev_node_create
(
deviceCode
,
productCode
,
gwdeviceCode
,
onlineStatus
,
buf
);
if
(
node
->
syn_opcode
!=
NULL
){
debug_log
(
LOG_CRITICAL_LEVEL
,
"111---->devNode->syn_opcode=%s[%d].
\n
"
,
node
->
syn_opcode
,
strlen
(
node
->
syn_opcode
));
}
else
{
debug_log
(
LOG_CRITICAL_LEVEL
,
"111---->devNode->syn_opcode.
\n
"
);
}
}
else
{
}
else
{
node
=
kk_map_dev_node_create_ex
(
deviceCode
,
productCode
,
gwdeviceCode
,
onlineStatus
);
node
=
kk_map_dev_node_create_ex
(
deviceCode
,
productCode
,
gwdeviceCode
,
onlineStatus
);
}
}
...
...
application/klansdk/kk_lan_ctrl.c
View file @
5af6ad5a
...
@@ -38,6 +38,53 @@ int match_opcode_pos(cJSON *array,const char *opcode,int ch)
...
@@ -38,6 +38,53 @@ int match_opcode_pos(cJSON *array,const char *opcode,int ch)
static
int
special_handling_for_compatibility
(
kk_map_dev_node_t
*
devNode
,
cJSON
*
opcode
,
cJSON
*
arg
,
cJSON
**
outVal
)
{
int
oType
=
0
;
int
ret
=
-
1
;
if
(
devNode
->
opearteType
==
NULL
||
opcode
==
NULL
||
arg
==
NULL
){
return
-
1
;
}
oType
=
atoi
(
devNode
->
opearteType
);
if
(
oType
>=
14001
&&
oType
<=
14500
){
debug_log
(
LOG_WARNING_LEVEL
,
"[err]v
\n
"
);
if
(
!
strcmp
(
opcode
->
valuestring
,
"FRESH_AIR_SPEED_SET"
)){
debug_log
(
LOG_WARNING_LEVEL
,
"[err]a
\n
"
);
if
(
arg
->
type
==
cJSON_String
){
debug_log
(
LOG_WARNING_LEVEL
,
"[err]aa
\n
"
);
if
(
!
strcmp
(
arg
->
valuestring
,
"STOP"
)
||
!
strcmp
(
arg
->
valuestring
,
"0"
)){
*
outVal
=
cJSON_CreateNumber
(
0
);
ret
=
0
;
debug_log
(
LOG_WARNING_LEVEL
,
"[err]0
\n
"
);
}
else
if
(
!
strcmp
(
arg
->
valuestring
,
"LOW"
)
||
!
strcmp
(
arg
->
valuestring
,
"1"
)){
*
outVal
=
cJSON_CreateNumber
(
1
);
ret
=
0
;
debug_log
(
LOG_WARNING_LEVEL
,
"[err]1
\n
"
);
}
else
if
(
!
strcmp
(
arg
->
valuestring
,
"MID"
)
||
!
strcmp
(
arg
->
valuestring
,
"2"
)){
*
outVal
=
cJSON_CreateNumber
(
2
);
ret
=
0
;
debug_log
(
LOG_WARNING_LEVEL
,
"[err]2
\n
"
);
}
else
if
(
!
strcmp
(
arg
->
valuestring
,
"HIGH"
)
||
!
strcmp
(
arg
->
valuestring
,
"3"
)){
*
outVal
=
cJSON_CreateNumber
(
3
);
ret
=
0
;
debug_log
(
LOG_WARNING_LEVEL
,
"[err]3
\n
"
);
}
else
{
debug_log
(
LOG_WARNING_LEVEL
,
"[err]para:%s
\n
"
,
arg
->
valuestring
);
}
}
}
}
return
ret
;
}
cJSON
*
kk_control_protocol_convert
(
kk_map_dev_node_t
*
devNode
,
int
nodeId
,
cJSON
*
arg
,
cJSON
*
opcode
)
cJSON
*
kk_control_protocol_convert
(
kk_map_dev_node_t
*
devNode
,
int
nodeId
,
cJSON
*
arg
,
cJSON
*
opcode
)
{
{
...
@@ -86,17 +133,22 @@ cJSON * kk_control_protocol_convert(kk_map_dev_node_t *devNode,int nodeId,cJSON
...
@@ -86,17 +133,22 @@ cJSON * kk_control_protocol_convert(kk_map_dev_node_t *devNode,int nodeId,cJSON
epNum
=
cJSON_GetObjectItem
(
newccuItem
,
"channel"
);
epNum
=
cJSON_GetObjectItem
(
newccuItem
,
"channel"
);
debug_log
(
LOG_FOCUS_LEVEL
,
"4
\n
"
);
debug_log
(
LOG_FOCUS_LEVEL
,
"4
\n
"
);
if
(
strcmp
(
o_dataType
->
valuestring
,
"map"
)
==
0
){
if
(
special_handling_for_compatibility
(
devNode
,
opcode
,
arg
,
&
val
)
!=
0
){
debug_log
(
LOG_FOCUS_LEVEL
,
"5
\n
"
);
if
(
strcmp
(
o_dataType
->
valuestring
,
"map"
)
==
0
){
val
=
map_type_convert
(
o_dataType
,
o_valueRange
,
arg
,
n_valueRange
);
debug_log
(
LOG_FOCUS_LEVEL
,
"5
\n
"
);
}
else
{
debug_log
(
LOG_FOCUS_LEVEL
,
"6
\n
"
);
val
=
map_type_convert
(
o_dataType
,
o_valueRange
,
arg
,
n_valueRange
);
val
=
msg_convert_value
(
n_dataType
,
o_dataType
,
arg
);
}
else
{
debug_log
(
LOG_FOCUS_LEVEL
,
"6
\n
"
);
val
=
msg_convert_value
(
n_dataType
,
o_dataType
,
arg
);
}
}
}
debug_log
(
LOG_FOCUS_LEVEL
,
"7
\n
"
);
debug_log
(
LOG_FOCUS_LEVEL
,
"7
\n
"
);
cJSON_AddStringToObject
(
params
,
"epNum"
,
epNum
->
valuestring
);
cJSON_AddStringToObject
(
params
,
"epNum"
,
epNum
->
valuestring
);
debug_log
(
LOG_FOCUS_LEVEL
,
"8
\n
"
);
debug_log
(
LOG_FOCUS_LEVEL
,
"8
\n
"
);
debug_log
(
LOG_WARNING_LEVEL
,
"[err]val->type:%d
\n
"
,
val
->
type
);
if
(
val
->
type
==
cJSON_False
){
if
(
val
->
type
==
cJSON_False
){
cJSON_AddFalseToObject
(
params
,
n_identifier
->
valuestring
);
cJSON_AddFalseToObject
(
params
,
n_identifier
->
valuestring
);
...
@@ -190,6 +242,55 @@ static int kk_indoorAir_ctrl_handle(char *epNum,cJSON *arg)
...
@@ -190,6 +242,55 @@ static int kk_indoorAir_ctrl_handle(char *epNum,cJSON *arg)
return
0
;
return
0
;
}
}
int
kk_lan_ctrl_ack
(
cJSON
*
nodeId
,
cJSON
*
opcode
,
cJSON
*
arg
)
{
cJSON
*
msg
=
NULL
;
cJSON
*
tmp_nodeId
=
NULL
,
*
tmp_opcode
=
NULL
,
*
tmp_arg
=
NULL
;
char
*
pData
=
NULL
;
char
acData
[
512
]
=
{
0
};
if
(
nodeId
==
NULL
||
opcode
==
NULL
||
arg
==
NULL
)
{
return
-
1
;
}
msg
=
cJSON_CreateObject
();
if
(
msg
){
memset
(
acData
,
0
,
sizeof
(
acData
));
pData
=
cJSON_Print
(
nodeId
);
snprintf
(
acData
,
sizeof
(
acData
),
"%s"
,
pData
);
tmp_nodeId
=
cJSON_Parse
(
acData
);
if
(
tmp_nodeId
==
NULL
){
return
-
1
;
}
memset
(
acData
,
0
,
sizeof
(
acData
));
pData
=
cJSON_Print
(
opcode
);
snprintf
(
acData
,
sizeof
(
acData
),
"%s"
,
pData
);
tmp_opcode
=
cJSON_Parse
(
acData
);
if
(
tmp_nodeId
==
NULL
){
return
-
1
;
}
memset
(
acData
,
0
,
sizeof
(
acData
));
pData
=
cJSON_Print
(
arg
);
snprintf
(
acData
,
sizeof
(
acData
),
"%s"
,
pData
);
tmp_arg
=
cJSON_Parse
(
acData
);
if
(
tmp_nodeId
==
NULL
){
return
-
1
;
}
cJSON_AddItemToObject
(
msg
,
"nodeid"
,
tmp_nodeId
);
cJSON_AddItemToObject
(
msg
,
"opcode"
,
tmp_opcode
);
cJSON_AddStringToObject
(
msg
,
"status"
,
"success"
);
cJSON_AddItemToObject
(
msg
,
"arg"
,
tmp_arg
);
}
send_msg_to_module
(
msg
);
return
0
;
}
int
kk_ccu_opcode_handle
(
cJSON
*
root
)
int
kk_ccu_opcode_handle
(
cJSON
*
root
)
{
{
cJSON
*
msg
;
cJSON
*
msg
;
...
@@ -253,11 +354,12 @@ int kk_ccu_opcode_handle(cJSON *root)
...
@@ -253,11 +354,12 @@ int kk_ccu_opcode_handle(cJSON *root)
if
(
kk_map_dev_search_by_deviceCode
(
deviceCode
,
&
dev
)
==
0
){
if
(
kk_map_dev_search_by_deviceCode
(
deviceCode
,
&
dev
)
==
0
){
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
kk_lan_ctrl_ack
(
nodeId
,
opcode
,
arg
);
cJSON
*
params
=
kk_control_protocol_convert
(
dev
,
atoi
(
nodeId
->
valuestring
),
arg
,
opcode
);
cJSON
*
params
=
kk_control_protocol_convert
(
dev
,
atoi
(
nodeId
->
valuestring
),
arg
,
opcode
);
msg
=
property_set
(
dev
->
productCode
,
dev
->
deviceCode
,
"*"
,
"*"
,
params
);
msg
=
property_set
(
dev
->
productCode
,
dev
->
deviceCode
,
"*"
,
"*"
,
params
);
kk_ipc_send_json
(
msg
);
kk_ipc_send_json
(
msg
);
debug_log
(
LOG_INFO_LEVEL
,
"MARK!
\n
"
);
}
else
{
}
else
{
WARNING_PRINT
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
WARNING_PRINT
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
...
...
application/klansdk/kk_lan_main.c
View file @
5af6ad5a
...
@@ -103,11 +103,33 @@ int prg_run_singleton(const char *prg)
...
@@ -103,11 +103,33 @@ int prg_run_singleton(const char *prg)
}
}
void
handler
(
int
signum
)
{
printf
(
"[sig]---------------------->signum=%d
\n
"
,
signum
);
if
(
signum
!=
17
){
exit
(
-
1
);
}
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
int
ret
=
0
;
int
ret
=
0
;
struct
sigaction
sa
;
/* setup alarm signal handler */
for
(
int
i
=
1
;
i
<
32
;
i
++
){
signal
(
i
,
handler
);
}
//signal(SIGPIPE, SIG_IGN);
open
(
"kk_lan"
,
LOG_PID
,
LOG_USER
);
open
(
"kk_lan"
,
LOG_PID
,
LOG_USER
);
//if(prg_run_singleton(argv[0])<0){
//if(prg_run_singleton(argv[0])<0){
...
...
application/klansdk/kk_lan_sync.c
View file @
5af6ad5a
...
@@ -593,14 +593,18 @@ int kk_sync_devices_status_to_sdk(cJSON *root)
...
@@ -593,14 +593,18 @@ int kk_sync_devices_status_to_sdk(cJSON *root)
kk_map_dev_node_t
*
n
=
NULL
;
kk_map_dev_node_t
*
n
=
NULL
;
cJSON
*
devStatusAry
=
cJSON_CreateArray
();
cJSON
*
devStatusAry
=
cJSON_CreateArray
();
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
_kk_map_dev_mutex_lock
();
_kk_map_dev_mutex_lock
();
list_for_each_entry_safe
(
node
,
n
,
&
ctx
->
dev_list
,
linked_list
,
kk_map_dev_node_t
){
list_for_each_entry_safe
(
node
,
n
,
&
ctx
->
dev_list
,
linked_list
,
kk_map_dev_node_t
){
if
(
node
->
syn_type
==
1
){
if
(
node
->
syn_type
==
1
){
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
_kk_sync_devices_status_arg_obj
(
node
,
devStatusAry
,
&
idx
);
_kk_sync_devices_status_arg_obj
(
node
,
devStatusAry
,
&
idx
);
}
else
{
}
else
{
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
_kk_sync_devices_status_arg_str
(
node
,
devStatusAry
,
&
idx
);
_kk_sync_devices_status_arg_str
(
node
,
devStatusAry
,
&
idx
);
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
//_kk_sync_devicestatus(node,devStatusAry);
//_kk_sync_devicestatus(node,devStatusAry);
}
}
...
@@ -1193,7 +1197,7 @@ static int kk_create_floors_to_sdk(cJSON *root,cJSON *data)
...
@@ -1193,7 +1197,7 @@ static int kk_create_floors_to_sdk(cJSON *root,cJSON *data)
//同步数据
//同步数据
int
kk_create_syncinfo_to_sdk
(
cJSON
*
payload
)
int
kk_create_syncinfo_to_sdk
(
cJSON
*
payload
,
int
push
)
{
{
cJSON
*
air_box_devices
;
cJSON
*
air_box_devices
;
cJSON
*
alarms
;
cJSON
*
alarms
;
...
@@ -1284,8 +1288,20 @@ int kk_create_syncinfo_to_sdk(cJSON *payload)
...
@@ -1284,8 +1288,20 @@ int kk_create_syncinfo_to_sdk(cJSON *payload)
#endif
#endif
char
*
out
=
cJSON_Print
(
root
);
char
*
out
=
cJSON_Print
(
root
);
cJSON
*
msg
=
old_ccu_msg_build_json
(
"*"
,
"SYNC_INFO"
,
NULL
,
root
);
printf
(
"out:%s
\n
"
,
out
);
cJSON
*
msg
=
NULL
;
if
(
push
==
1
){
msg
=
old_ccu_msg_build_json
(
"*"
,
"SYNC_INFO_PUSH"
,
NULL
,
root
);
}
else
{
msg
=
old_ccu_msg_build_json
(
"*"
,
"SYNC_INFO"
,
NULL
,
root
);
}
send_msg_to_module
(
msg
);
send_msg_to_module
(
msg
);
cJSON_Delete
(
msg
);
cJSON_Delete
(
msg
);
free
(
out
);
free
(
out
);
...
...
application/klansdk/kk_lan_sync.h
View file @
5af6ad5a
...
@@ -45,7 +45,7 @@ cJSON *kk_sync_scence_to_sdk(cJSON *root,cJSON *data);
...
@@ -45,7 +45,7 @@ cJSON *kk_sync_scence_to_sdk(cJSON *root,cJSON *data);
int
kk_sync_devices_to_sdk
(
cJSON
*
root
,
cJSON
*
data
);
int
kk_sync_devices_to_sdk
(
cJSON
*
root
,
cJSON
*
data
);
int
kk_sync_devices_status_to_sdk
(
cJSON
*
root
);
int
kk_sync_devices_status_to_sdk
(
cJSON
*
root
);
int
kk_create_syncinfo_to_sdk
(
cJSON
*
payload
);
int
kk_create_syncinfo_to_sdk
(
cJSON
*
payload
,
int
push
);
int
kk_send_indoorAir_status
(
cJSON
*
info
);
int
kk_send_indoorAir_status
(
cJSON
*
info
);
...
...
application/klansdk/kk_login_handle.c
View file @
5af6ad5a
...
@@ -26,6 +26,18 @@ static kk_clientInfo_t s_ConnInfo[LISTEN_MAX] = {0};
...
@@ -26,6 +26,18 @@ static kk_clientInfo_t s_ConnInfo[LISTEN_MAX] = {0};
static
pthread_mutex_t
data_mutex
;
static
pthread_mutex_t
data_mutex
;
fd_set
fds
;
fd_set
fds
;
void
tcp_data_mutex_lock
(
void
)
{
pthread_mutex_lock
(
&
data_mutex
);
}
void
tcp_data_mutex_unlock
(
void
)
{
pthread_mutex_unlock
(
&
data_mutex
);
}
int
kk_send_data_to_sdk
(
char
*
buf
)
int
kk_send_data_to_sdk
(
char
*
buf
)
{
{
char
*
tmpBuf
=
NULL
;
char
*
tmpBuf
=
NULL
;
...
@@ -39,9 +51,13 @@ int kk_send_data_to_sdk(char *buf)
...
@@ -39,9 +51,13 @@ int kk_send_data_to_sdk(char *buf)
strcat
(
tmpBuf
,
"$"
);
strcat
(
tmpBuf
,
"$"
);
INFO_PRINT
(
"tmpBuf:%s
\n
"
,
tmpBuf
);
INFO_PRINT
(
"tmpBuf:%s
\n
"
,
tmpBuf
);
for
(
i
=
0
;
i
<
LISTEN_MAX
;
i
++
){
for
(
i
=
0
;
i
<
LISTEN_MAX
;
i
++
){
tcp_data_mutex_lock
();
if
(
s_ConnInfo
[
i
].
socketfd
!=
-
1
){
if
(
s_ConnInfo
[
i
].
socketfd
!=
-
1
){
send
(
s_ConnInfo
[
i
].
socketfd
,
tmpBuf
,
strlen
(
tmpBuf
),
0
);
send
(
s_ConnInfo
[
i
].
socketfd
,
tmpBuf
,
strlen
(
tmpBuf
),
0
);
}
}
tcp_data_mutex_unlock
();
}
}
free
(
tmpBuf
);
free
(
tmpBuf
);
...
@@ -81,9 +97,11 @@ static int kk_check_is_connect(char *ip){
...
@@ -81,9 +97,11 @@ static int kk_check_is_connect(char *ip){
}
}
for
(
i
=
0
;
i
<
LISTEN_MAX
;
i
++
){
for
(
i
=
0
;
i
<
LISTEN_MAX
;
i
++
){
if
(
s_ConnInfo
[
i
].
socketfd
!=
-
1
&&
strcmp
(
s_ConnInfo
[
i
].
ip
,
ip
)
==
0
){
if
(
s_ConnInfo
[
i
].
socketfd
!=
-
1
&&
strcmp
(
s_ConnInfo
[
i
].
ip
,
ip
)
==
0
){
pthread_mutex_lock
(
&
data_mutex
);
close
(
s_ConnInfo
[
i
].
socketfd
);
close
(
s_ConnInfo
[
i
].
socketfd
);
s_ConnInfo
[
i
].
socketfd
=
-
1
;
s_ConnInfo
[
i
].
socketfd
=
-
1
;
memset
(
s_ConnInfo
[
i
].
ip
,
0x0
,
sizeof
(
s_ConnInfo
[
i
].
ip
));
memset
(
s_ConnInfo
[
i
].
ip
,
0x0
,
sizeof
(
s_ConnInfo
[
i
].
ip
));
pthread_mutex_unlock
(
&
data_mutex
);
return
1
;
return
1
;
}
}
}
}
...
@@ -145,10 +163,12 @@ void *TCPServer()
...
@@ -145,10 +163,12 @@ void *TCPServer()
FD_SET
(
Listenfd
,
&
server_fd_set
);
FD_SET
(
Listenfd
,
&
server_fd_set
);
for
(
i
=
0
;
i
<
LISTEN_MAX
;
i
++
)
for
(
i
=
0
;
i
<
LISTEN_MAX
;
i
++
)
{
{
pthread_mutex_lock
(
&
data_mutex
);
if
(
s_ConnInfo
[
i
].
socketfd
>
0
)
if
(
s_ConnInfo
[
i
].
socketfd
>
0
)
{
{
FD_SET
(
s_ConnInfo
[
i
].
socketfd
,
&
server_fd_set
);
FD_SET
(
s_ConnInfo
[
i
].
socketfd
,
&
server_fd_set
);
}
}
pthread_mutex_unlock
(
&
data_mutex
);
}
}
ret
=
select
(
max_fd
+
1
,
&
server_fd_set
,
NULL
,
NULL
,
&
time_out
);
ret
=
select
(
max_fd
+
1
,
&
server_fd_set
,
NULL
,
NULL
,
&
time_out
);
if
(
ret
<=
0
){
if
(
ret
<=
0
){
...
@@ -199,8 +219,10 @@ void *TCPServer()
...
@@ -199,8 +219,10 @@ void *TCPServer()
{
{
memset
(
Buf
,
0
,
sizeof
(
Buf
));
memset
(
Buf
,
0
,
sizeof
(
Buf
));
pthread_mutex_lock
(
&
data_mutex
);
ret
=
recv
(
s_ConnInfo
[
index
].
socketfd
,
Buf
,
sizeof
(
Buf
),
0
);
//最后一个参数为0,表示默认阻塞接收,前面select解除了阻塞说明有数据可读
ret
=
recv
(
s_ConnInfo
[
index
].
socketfd
,
Buf
,
sizeof
(
Buf
),
0
);
//最后一个参数为0,表示默认阻塞接收,前面select解除了阻塞说明有数据可读
pthread_mutex_unlock
(
&
data_mutex
);
if
(
ret
>
0
)
if
(
ret
>
0
)
{
{
printf
(
"recv->buf:%s
\n
"
,
Buf
);
printf
(
"recv->buf:%s
\n
"
,
Buf
);
...
@@ -234,14 +256,19 @@ int kk_login_init()
...
@@ -234,14 +256,19 @@ int kk_login_init()
pthread_t
threadID
=
0
;
pthread_t
threadID
=
0
;
DEBUG_PRINT
(
"kk_login_init Init OK!
\n
"
);
DEBUG_PRINT
(
"kk_login_init Init OK!
\n
"
);
for
(
i
=
0
;
i
<
LISTEN_MAX
;
i
++
){
s_ConnInfo
[
i
].
socketfd
=
-
1
;
memset
(
s_ConnInfo
[
i
].
ip
,
0x0
,
sizeof
(
s_ConnInfo
[
i
].
ip
));
}
if
(
pthread_mutex_init
(
&
data_mutex
,
NULL
)
!=
0
)
{
if
(
pthread_mutex_init
(
&
data_mutex
,
NULL
)
!=
0
)
{
ERROR_PRINT
(
"pthread_mutex_init kk_login_init err
\n
"
);
ERROR_PRINT
(
"pthread_mutex_init kk_login_init err
\n
"
);
return
-
1
;
return
-
1
;
}
}
pthread_mutex_lock
(
&
data_mutex
);
for
(
i
=
0
;
i
<
LISTEN_MAX
;
i
++
){
s_ConnInfo
[
i
].
socketfd
=
-
1
;
memset
(
s_ConnInfo
[
i
].
ip
,
0x0
,
sizeof
(
s_ConnInfo
[
i
].
ip
));
}
pthread_mutex_unlock
(
&
data_mutex
);
pthread_attr_t
attr
;
pthread_attr_t
attr
;
pthread_attr_init
(
&
attr
);
pthread_attr_init
(
&
attr
);
pthread_attr_setdetachstate
(
&
attr
,
PTHREAD_CREATE_DETACHED
);
pthread_attr_setdetachstate
(
&
attr
,
PTHREAD_CREATE_DETACHED
);
...
...
application/klansdk/kk_login_handle.h
View file @
5af6ad5a
...
@@ -7,4 +7,8 @@
...
@@ -7,4 +7,8 @@
#define SERVER_LISTEN_PORT 5000
#define SERVER_LISTEN_PORT 5000
int
kk_login_init
();
int
kk_login_init
();
int
kk_send_data_to_sdk
(
char
*
buf
);
int
kk_send_data_to_sdk
(
char
*
buf
);
void
tcp_data_mutex_lock
(
void
);
void
tcp_data_mutex_unlock
(
void
);
#endif
#endif
\ No newline at end of file
application/klansdk/kk_oldccu_msg.c
View file @
5af6ad5a
...
@@ -70,7 +70,9 @@ int send_msg_to_module(cJSON *root)
...
@@ -70,7 +70,9 @@ int send_msg_to_module(cJSON *root)
debug_log
(
LOG_INFO_LEVEL
,
"[lan->module]
\n
%s
\n
"
,
msg
);
debug_log
(
LOG_INFO_LEVEL
,
"[lan->module]
\n
%s
\n
"
,
msg
);
cJSON_Minify
(
msg
);
cJSON_Minify
(
msg
);
kk_send_data_to_sdk
(
msg
);
kk_send_data_to_sdk
(
msg
);
free
(
msg
);
free
(
msg
);
}
}
return
0
;
return
0
;
...
@@ -205,7 +207,6 @@ static int _kk_lan_sync_device_status(const char *deviceCode,kk_map_dev_node_t *
...
@@ -205,7 +207,6 @@ static int _kk_lan_sync_device_status(const char *deviceCode,kk_map_dev_node_t *
return
-
1
;
return
-
1
;
}
}
debug_log
(
LOG_CRITICAL_LEVEL
,
"---->devNode->syn_opcode=%s[%d].
\n
"
,
devNode
->
syn_opcode
,
strlen
(
devNode
->
syn_opcode
));
if
((
arg
=
_kk_sync_devicestatus_arg_build
(
devNode
))
==
NULL
){
if
((
arg
=
_kk_sync_devicestatus_arg_build
(
devNode
))
==
NULL
){
debug_log
(
LOG_DEBUG_LEVEL
,
"[err] arg.
\n
"
);
debug_log
(
LOG_DEBUG_LEVEL
,
"[err] arg.
\n
"
);
...
@@ -353,22 +354,16 @@ static int kk_lan_property_convert(const char *deviceCode,kk_map_dev_node_t *dev
...
@@ -353,22 +354,16 @@ static int kk_lan_property_convert(const char *deviceCode,kk_map_dev_node_t *dev
if
(
devNode
->
syn_opcode
!=
NULL
){
debug_log
(
LOG_CRITICAL_LEVEL
,
"---->devNode->syn_opcode=%s[%d].
\n
"
,
devNode
->
syn_opcode
,
strlen
(
devNode
->
syn_opcode
));
}
kk_lan_replace_val_to_obj
(
n_item
,
valObj
,
"value"
);
kk_lan_replace_val_to_obj
(
n_item
,
valObj
,
"value"
);
if
(
devNode
->
syn_opcode
!=
NULL
){
debug_log
(
LOG_CRITICAL_LEVEL
,
"---->devNode->syn_opcode=%s[%d].
\n
"
,
devNode
->
syn_opcode
,
strlen
(
devNode
->
syn_opcode
));
}
if
((
args
=
ccu_value_convert
(
n_dataType
,
n_valueRange
,
o_dataType
,
o_valueRange
,
valObj
))
!=
NULL
){
if
((
args
=
ccu_value_convert
(
n_dataType
,
n_valueRange
,
o_dataType
,
o_valueRange
,
valObj
))
!=
NULL
){
if
(
devNode
->
syn_opcode
!=
NULL
){
debug_log
(
LOG_CRITICAL_LEVEL
,
"---->devNode->syn_opcode=%s[%d].
\n
"
,
devNode
->
syn_opcode
,
strlen
(
devNode
->
syn_opcode
));
}
_kk_lan_update_device_status
(
nodeId
,
opcode
,
args
,
devNode
->
syn_opcode
);
_kk_lan_update_device_status
(
nodeId
,
opcode
,
args
,
devNode
->
syn_opcode
);
//todo :
//todo :
...
@@ -379,9 +374,7 @@ static int kk_lan_property_convert(const char *deviceCode,kk_map_dev_node_t *dev
...
@@ -379,9 +374,7 @@ static int kk_lan_property_convert(const char *deviceCode,kk_map_dev_node_t *dev
}
}
if
(
devNode
->
syn_opcode
!=
NULL
){
debug_log
(
LOG_CRITICAL_LEVEL
,
"---->devNode->syn_opcode=%s[%d].
\n
"
,
devNode
->
syn_opcode
,
strlen
(
devNode
->
syn_opcode
));
}
_kk_lan_sync_device_status
(
deviceCode
,
devNode
);
_kk_lan_sync_device_status
(
deviceCode
,
devNode
);
return
0
;
return
0
;
...
@@ -453,7 +446,7 @@ void kk_lan_add_scene_notify(const char* scene_id)
...
@@ -453,7 +446,7 @@ void kk_lan_add_scene_notify(const char* scene_id)
{
{
debug_log
(
LOG_FOCUS_LEVEL
,
"[notify] add scene(%s).
\n
"
,
scene_id
);
debug_log
(
LOG_FOCUS_LEVEL
,
"[notify] add scene(%s).
\n
"
,
scene_id
);
kk_handle_sync_info
();
kk_handle_sync_
push_
info
();
}
}
//删除场景通知
//删除场景通知
...
@@ -465,7 +458,7 @@ void kk_lan_delete_scene_notify(const char* scene_id)
...
@@ -465,7 +458,7 @@ void kk_lan_delete_scene_notify(const char* scene_id)
send_msg_to_module
(
msg
);
send_msg_to_module
(
msg
);
cJSON_Delete
(
msg
);
cJSON_Delete
(
msg
);
kk_handle_sync_info
();
kk_handle_sync_
push_
info
();
}
}
//布防撤防状态通知(0-离家布防、1-撤防、2-在家布防、3-区域布防)
//布防撤防状态通知(0-离家布防、1-撤防、2-在家布防、3-区域布防)
...
@@ -539,7 +532,7 @@ static int _kk_lan_delete_device(const char *deviceCode)
...
@@ -539,7 +532,7 @@ static int _kk_lan_delete_device(const char *deviceCode)
kk_lan_db_node_delete
(
deviceCode
);
kk_lan_db_node_delete
(
deviceCode
);
if
(
num
){
if
(
num
){
kk_handle_sync_info
();
kk_handle_sync_
push_
info
();
}
}
return
0
;
return
0
;
}
}
...
@@ -569,6 +562,6 @@ void device_add_sync(cJSON *payload)
...
@@ -569,6 +562,6 @@ void device_add_sync(cJSON *payload)
{
{
//NEW_DEVICES
//NEW_DEVICES
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
kk_handle_sync_info
();
kk_handle_sync_
push_
info
();
}
}
application/klansdk/kk_opcode.h
View file @
5af6ad5a
...
@@ -3,6 +3,9 @@
...
@@ -3,6 +3,9 @@
#define SYNC_MSG_TYPE "/thing/service/syncinfo"
#define SYNC_MSG_TYPE "/thing/service/syncinfo"
#define SYNC_MSG_TYPE_REPLY "/thing/service/syncinfo_reply"
#define SYNC_MSG_TYPE_REPLY "/thing/service/syncinfo_reply"
#define SYNCPUSH_MSG_TYPE "/thing/service/syncinfopush"
#define SYNCPUSH_MSG_TYPE_REPLY "/thing/service/syncinfopush_reply"
#define DATA_STRING "data"
#define DATA_STRING "data"
#define VALUE_STRING "value"
#define VALUE_STRING "value"
#define OPCODEMAP_STRING "opcodemap"
#define OPCODEMAP_STRING "opcodemap"
...
...
midware/midware/dm/kk_dm_msg.c
View file @
5af6ad5a
...
@@ -783,6 +783,28 @@ int dm_msg_thing_syncinfo_reply(void){
...
@@ -783,6 +783,28 @@ int dm_msg_thing_syncinfo_reply(void){
free
(
info
);
free
(
info
);
return
SUCCESS_RETURN
;
return
SUCCESS_RETURN
;
}
}
int
dm_msg_thing_syncinfopush_reply
(
void
){
kk_msg_request_payload_t
request
;
kk_msg_response_t
response
;
dm_mgr_dev_node_t
*
node
=
NULL
;
char
*
info
=
NULL
;
int
res
=
0
;
memset
(
&
request
,
0
,
sizeof
(
kk_msg_request_payload_t
));
memset
(
&
response
,
0
,
sizeof
(
kk_msg_response_t
));
res
=
dm_mgr_search_dev_by_devid
(
KK_DM_DEVICE_CCU_DEVICEID
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
response
.
msgTypeStr
=
KK_THING_SERVICE_SYNCINFOPUSH_REPLY
;
memcpy
(
response
.
productCode
,
node
->
productCode
,
strlen
(
node
->
productCode
));
memcpy
(
response
.
deviceCode
,
node
->
deviceCode
,
strlen
(
node
->
deviceCode
));
response
.
code
=
(
res
==
SUCCESS_RETURN
)
?
(
IOTX_DM_ERR_CODE_SUCCESS
)
:
(
IOTX_DM_ERR_CODE_REQUEST_ERROR
);
info
=
kk_sync_get_info
();
dm_msg_response
(
&
request
,
&
response
,
info
,
strlen
(
info
),
NULL
);
free
(
info
);
return
SUCCESS_RETURN
;
}
int
dm_msg_thing_syncdeviceinfo_reply
(
cJSON
*
msgId
){
int
dm_msg_thing_syncdeviceinfo_reply
(
cJSON
*
msgId
){
...
...
midware/midware/dm/kk_dm_msg.h
View file @
5af6ad5a
...
@@ -82,6 +82,7 @@ const char DM_MSG_INFO[] DM_READ_ONLY;
...
@@ -82,6 +82,7 @@ const char DM_MSG_INFO[] DM_READ_ONLY;
#define KK_THING_METHOD_UPDATESCENC "thing.service.updateScene"
#define KK_THING_METHOD_UPDATESCENC "thing.service.updateScene"
#define KK_THING_METHOD_EXECUTESCENE "thing.service.executeScene"
#define KK_THING_METHOD_EXECUTESCENE "thing.service.executeScene"
#define KK_THING_METHOD_ADDSCENC "thing.service.addScene"
#define KK_THING_METHOD_ADDSCENC "thing.service.addScene"
#define KK_THING_SERVICE_SYNCINFOPUSH "/thing/service/syncinfopush"
#define KK_THING_SERVICE_SYNCINFO "/thing/service/syncinfo"
#define KK_THING_SERVICE_SYNCINFO "/thing/service/syncinfo"
#define KK_THING_SERVICE_SYNCDEVICEINFO "/thing/service/syncDeviceInfo"
#define KK_THING_SERVICE_SYNCDEVICEINFO "/thing/service/syncDeviceInfo"
#define KK_THING_SERVICE_SYNCDEVICEINFO_REPLY "/thing/service/syncDeviceInfo_reply"
#define KK_THING_SERVICE_SYNCDEVICEINFO_REPLY "/thing/service/syncDeviceInfo_reply"
...
@@ -90,6 +91,9 @@ const char DM_MSG_INFO[] DM_READ_ONLY;
...
@@ -90,6 +91,9 @@ const char DM_MSG_INFO[] DM_READ_ONLY;
#define KK_THING_SERVICE_SYNCINFO_REPLY "/thing/service/syncinfo_reply"
#define KK_THING_SERVICE_SYNCINFO_REPLY "/thing/service/syncinfo_reply"
#define KK_THING_SERVICE_SYNCINFOPUSH_REPLY "/thing/service/syncinfopush_reply"
#define KK_THING_EVENT_MESSAGE "/thing/event/"
#define KK_THING_EVENT_MESSAGE "/thing/event/"
#define KK_THING_SERVICE_GETGUARDSENSORS "/thing/service/getGuardSensors"
#define KK_THING_SERVICE_GETGUARDSENSORS "/thing/service/getGuardSensors"
#define KK_THING_EVENT_POST "/post"
#define KK_THING_EVENT_POST "/post"
...
@@ -146,6 +150,8 @@ int kk_msg_execute_scene_set(const char* params,const char *fatherDeviceCode,int
...
@@ -146,6 +150,8 @@ int kk_msg_execute_scene_set(const char* params,const char *fatherDeviceCode,int
int
kk_msg_execute_scene_action
(
const
char
*
params
,
const
char
*
fatherDeviceCode
);
int
kk_msg_execute_scene_action
(
const
char
*
params
,
const
char
*
fatherDeviceCode
);
int
kk_msg_execute_scene_delete
(
const
char
*
params
,
const
char
*
fatherDeviceCode
);
int
kk_msg_execute_scene_delete
(
const
char
*
params
,
const
char
*
fatherDeviceCode
);
int
dm_msg_thing_syncinfo_reply
(
void
);
int
dm_msg_thing_syncinfo_reply
(
void
);
int
dm_msg_thing_syncinfopush_reply
(
void
);
//const char DM_URI_SYS_PREFIX[] DM_READ_ONLY = "/sys/%s/%s/";
//const char DM_URI_SYS_PREFIX[] DM_READ_ONLY = "/sys/%s/%s/";
...
...
midware/midware/dm/kk_linkkit.c
View file @
5af6ad5a
...
@@ -1362,6 +1362,9 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
...
@@ -1362,6 +1362,9 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
else
if
(
strcmp
(
typeJson
->
valuestring
,
KK_THING_SERVICE_SYNCINFO
)
==
0
){
else
if
(
strcmp
(
typeJson
->
valuestring
,
KK_THING_SERVICE_SYNCINFO
)
==
0
){
INFO_PRINT
(
"SYNCINFO service
\n
"
);
INFO_PRINT
(
"SYNCINFO service
\n
"
);
dm_msg_thing_syncinfo_reply
();
dm_msg_thing_syncinfo_reply
();
}
else
if
(
strcmp
(
typeJson
->
valuestring
,
KK_THING_SERVICE_SYNCINFOPUSH
)
==
0
){
INFO_PRINT
(
"SYNCINFOPUSH service
\n
"
);
dm_msg_thing_syncinfopush_reply
();
}
}
else
if
(
strcmp
(
typeJson
->
valuestring
,
KK_THING_SERVICE_BINDSCENE
)
==
0
){
else
if
(
strcmp
(
typeJson
->
valuestring
,
KK_THING_SERVICE_BINDSCENE
)
==
0
){
INFO_PRINT
(
"bind scene
\n
"
);
INFO_PRINT
(
"bind scene
\n
"
);
...
...
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