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
6817d452
Commit
6817d452
authored
Aug 31, 2020
by
chen.weican
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】增加midware层对于mqtt连接状态的check
【提交人】陈伟灿
parent
1ed830cc
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
131 additions
and
9 deletions
+131
-9
application/kcloud/kcloud_data_handle.c
application/kcloud/kcloud_data_handle.c
+12
-3
application/kcloud/mqtt_api.c
application/kcloud/mqtt_api.c
+8
-2
midware/midware/dm/kk_dm_api.c
midware/midware/dm/kk_dm_api.c
+9
-0
midware/midware/dm/kk_dm_mng.c
midware/midware/dm/kk_dm_mng.c
+53
-0
midware/midware/dm/kk_dm_msg.c
midware/midware/dm/kk_dm_msg.c
+34
-1
midware/midware/dm/kk_dm_msg.h
midware/midware/dm/kk_dm_msg.h
+2
-2
midware/midware/dm/kk_linkkit.c
midware/midware/dm/kk_linkkit.c
+7
-0
midware/midware/midware.c
midware/midware/midware.c
+5
-0
zlog.conf
zlog.conf
+1
-1
No files found.
application/kcloud/kcloud_data_handle.c
View file @
6817d452
...
...
@@ -24,6 +24,7 @@
#define KK_FILTER_STATUS_OFFLINE_REPLY "/thing/status/offline_reply"
#define KK_CLOUDSTATE_MSG "/thing/ccu/cloudstate"
#define KK_CLOUDSTATE_MSG_REPLY "/thing/ccu/cloudstate_reply"
const
char
DM_MSG_TO_MIDDWARE
[]
=
"{
\"
msgtype
\"
:
\"
%s
\"
,
\"
productCode
\"
:
\"
%s
\"
,
\"
deviceCode
\"
:
\"
%s
\"
}"
;
#define KK_TOPIC_SERVICE_DELIMITER '/'
...
...
@@ -54,6 +55,14 @@ int _kk_sendto_cloud(cJSON *root)
//If topo delete,need UnSubscribe the topic
if
(
strstr
(
msgTypeStr
->
valuestring
,
KK_FILTER_DELETE_TOPIC
)
!=
NULL
){
KK_Subdev_UnSubscribe
(
pData
);
free
(
topic
);
return
0
;
}
else
if
(
strstr
(
msgTypeStr
->
valuestring
,
KK_CLOUDSTATE_MSG
)
!=
NULL
){
KK_Send_CloudState
(
kk_get_cloud_status
());
free
(
topic
);
return
0
;
}
char
*
out
=
cJSON_Print
(
pData
);
...
...
@@ -215,7 +224,7 @@ static char * _kk_data_create(const char *topic,const char *data)
return
out
;
//free(out); /* Print to text, Delete the cJSON, print it, release the string. */
}
const
char
DM_MSG_CLOUDSTATE
[]
=
"{
\"
msgId
\"
:
\"
1
\"
,
\"
version
\"
:
\"
1.0
\"
,
\"
params
\"
:{
\"
IOTCloudState
\"
:
\"
%d
\"
},
\"
method
\"
:
\"
/thing/ccu/cloudstate
\"
}"
;
const
char
DM_MSG_CLOUDSTATE
[]
=
"{
\"
msgId
\"
:
\"
1
\"
,
\"
version
\"
:
\"
1.0
\"
,
\"
params
\"
:{
\"
IOTCloudState
\"
:
\"
%d
\"
},
\"
method
\"
:
\"
thing.ccu.cloudstate_reply
\"
}"
;
int
KK_Send_CloudState
(
int
state
)
{
...
...
@@ -226,14 +235,14 @@ int KK_Send_CloudState(int state)
cJSON
*
root
;
char
*
out
;
infoStr_len
=
strlen
(
DM_MSG_TO_MIDDWARE
)
+
strlen
(
KK_CLOUDSTATE_MSG
)
+
10
;
infoStr_len
=
strlen
(
DM_MSG_TO_MIDDWARE
)
+
strlen
(
KK_CLOUDSTATE_MSG
_REPLY
)
+
10
;
infoStr
=
malloc
(
infoStr_len
);
if
(
infoStr
==
NULL
){
ERROR_PRINT
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
return
-
1
;
}
memset
(
infoStr
,
0x0
,
infoStr_len
);
snprintf
(
infoStr
,
infoStr_len
,
DM_MSG_TO_MIDDWARE
,
KK_CLOUDSTATE_MSG
,
""
,
""
);
snprintf
(
infoStr
,
infoStr_len
,
DM_MSG_TO_MIDDWARE
,
KK_CLOUDSTATE_MSG
_REPLY
,
""
,
""
);
payloadStr_len
=
strlen
(
DM_MSG_CLOUDSTATE
)
+
10
;
payloadStr
=
malloc
(
payloadStr_len
);
...
...
application/kcloud/mqtt_api.c
View file @
6817d452
...
...
@@ -10,7 +10,11 @@ static const char* OPT_SUB = "MQTTAsync_subscribe";
static
const
char
*
OPT_UNSUB
=
"MQTTAsync_unsubscribe"
;
static
MQTTAsync
s_Client
;
static
int
s_mqttStop
=
0
;
static
int
s_cloudStatus
=
0
;
int
kk_get_cloud_status
(
void
){
return
s_cloudStatus
;
}
/*Connect lost callback*/
static
void
connlost
(
void
*
context
,
char
*
cause
)
{
...
...
@@ -26,7 +30,8 @@ static void connlost(void *context, char *cause)
INFO_PRINT
(
"
\n
Connection lost
\n
"
);
INFO_PRINT
(
"cause: %s
\n
"
,
cause
);
KK_Send_CloudState
(
0
);
s_cloudStatus
=
0
;
KK_Send_CloudState
(
s_cloudStatus
);
conn_opts
.
keepAliveInterval
=
20
;
conn_opts
.
cleansession
=
1
;
if
((
rc
=
MQTTAsync_connect
(
client
,
&
conn_opts
))
!=
MQTTASYNC_SUCCESS
)
...
...
@@ -98,7 +103,8 @@ void onConnectFailure(void* context, MQTTAsync_failureData* response)
void
onConnect
(
void
*
context
,
MQTTAsync_successData
*
response
)
{
INFO_PRINT
(
"Successful connection
\n
"
);
KK_Send_CloudState
(
1
);
s_cloudStatus
=
1
;
KK_Send_CloudState
(
s_cloudStatus
);
}
...
...
midware/midware/dm/kk_dm_api.c
View file @
6817d452
...
...
@@ -104,6 +104,15 @@ int iotx_dm_subdev_topo_del(_IN_ int devid)
_dm_api_unlock
();
return
res
;
}
int
iotx_dm_ccu_cloud_check
(
void
)
{
int
res
=
0
;
_dm_api_lock
();
res
=
dm_mgr_ccu_status_cloud
(
0
);
_dm_api_unlock
();
return
res
;
}
int
iotx_dm_dev_online
(
_IN_
int
devid
)
{
...
...
midware/midware/dm/kk_dm_mng.c
View file @
6817d452
...
...
@@ -943,6 +943,59 @@ int dm_mgr_upstream_thing_list_found(_IN_ int devid)
return
res
;
}
const
char
DM_URI_STATUS_CLOUD
[]
=
"/thing/ccu/cloudstate"
;
int
dm_mgr_ccu_status_cloud
(
_IN_
int
devid
)
{
int
res
=
0
;
dm_mgr_dev_node_t
*
node
=
NULL
;
dm_mgr_dev_node_t
*
gw_node
=
NULL
;
dm_msg_request_t
request
;
if
(
devid
<
0
)
{
return
INVALID_PARAMETER
;
}
memset
(
&
request
,
0
,
sizeof
(
dm_msg_request_t
));
res
=
dm_mgr_search_dev_by_devid
(
devid
,
&
node
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
memcpy
(
request
.
productCode
,
node
->
productCode
,
strlen
(
node
->
productCode
));
memcpy
(
request
.
deviceCode
,
node
->
deviceCode
,
strlen
(
node
->
deviceCode
));
request
.
msgTypeStr
=
DM_URI_STATUS_CLOUD
;
/* Get Params And Method */
res
=
dm_msg_status_cloud
(
node
->
productCode
,
node
->
deviceCode
,
&
request
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
printf
(
"[%s][%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
/* Get Msg ID */
request
.
msgid
=
iotx_report_id
();
/* Get Dev ID */
request
.
devid
=
devid
;
/* Callback */
//request.callback = dm_client_combine_login_reply;
/* Send Message To Cloud */
res
=
dm_msg_request
(
&
request
);
if
(
res
==
SUCCESS_RETURN
)
{
res
=
request
.
msgid
;
}
free
(
request
.
params
);
return
res
;
}
const
char
DM_URI_STATUS_ONLINE
[]
=
"/thing/status/online"
;
int
dm_mgr_upstream_status_online
(
_IN_
int
devid
)
{
...
...
midware/midware/dm/kk_dm_msg.c
View file @
6817d452
...
...
@@ -259,6 +259,40 @@ int dm_msg_thing_topo_delete(_IN_ char deviceCode[DEVICE_CODE_MAXLEN],_OU_ dm_ms
return
SUCCESS_RETURN
;
}
const
char
DM_MSG_STATUS_CLOUD_METHOD
[]
DM_READ_ONLY
=
"thing.ccu.cloudstate"
;
const
char
DM_MSG_STATUS_CLOUD
[]
DM_READ_ONLY
=
"{
\"
deviceCode
\"
:
\"
%s
\"
}"
;
int
dm_msg_status_cloud
(
_IN_
char
productCode
[
PRODUCT_CODE_MAXLEN
],
_IN_
char
deviceCode
[
DEVICE_CODE_MAXLEN
],
_OU_
dm_msg_request_t
*
request
)
{
char
*
params
=
NULL
;
int
params_len
=
0
;
if
(
request
==
NULL
||
deviceCode
==
NULL
||
productCode
==
NULL
||
(
strlen
(
deviceCode
)
>=
DEVICE_CODE_MAXLEN
)
||
(
strlen
(
productCode
)
>=
PRODUCT_CODE_MAXLEN
)
||
(
strlen
(
request
->
deviceCode
)
>=
DEVICE_CODE_MAXLEN
))
{
return
INVALID_PARAMETER
;
}
/* Params */
request
->
method
=
(
char
*
)
DM_MSG_STATUS_CLOUD_METHOD
;
params_len
=
strlen
(
DM_MSG_STATUS_CLOUD
)
+
strlen
(
deviceCode
)
+
1
;
params
=
malloc
(
params_len
);
if
(
params
==
NULL
)
{
return
DM_MEMORY_NOT_ENOUGH
;
}
memset
(
params
,
0
,
params_len
);
HAL_Snprintf
(
params
,
params_len
,
DM_MSG_STATUS_CLOUD
,
deviceCode
);
request
->
params
=
params
;
request
->
params_len
=
strlen
(
request
->
params
);
return
SUCCESS_RETURN
;
}
const
char
DM_MSG_COMBINE_STATUS_ONLINE_METHOD
[]
DM_READ_ONLY
=
"thing.status.online"
;
const
char
DM_MSG_COMBINE_STATUS_ONLINE
[]
DM_READ_ONLY
=
"{
\"
deviceCode
\"
:
\"
%s
\"
}"
;
...
...
@@ -536,7 +570,6 @@ int dm_msg_request (_IN_ dm_msg_request_t *request)
free
(
payload
);
return
FAIL_RETURN
;
}
//if (type & DM_MSG_DEST_CLOUD) {
// dm_client_publish(uri, (unsigned char *)payload, strlen(payload), request->callback);
kk_sendData2app
(
req_info
,
payload
);
...
...
midware/midware/dm/kk_dm_msg.h
View file @
6817d452
...
...
@@ -44,10 +44,10 @@ const char DM_MSG_INFO[] DM_READ_ONLY;
#define KK_REGISTER_TOPIC_REPLY "/thing/sub/register_reply"
#define KK_ADD_TOPIC_REPLY "/thing/topo/add_reply"
#define KK_LOGIN_TOPIC_REPLY "/thing/combine/login_reply"
#define KK_ONLINE_TOPIC_REPLY
"/thing/status/online_reply"
#define KK_ONLINE_TOPIC_REPLY "/thing/status/online_reply"
#define KK_THING_SERVICE_PROPERTY_SET "/thing/service/property/set"
#define KK_THING_OTA_DEVICE_UPGRADE "/ota/device/upgrade"
#define KK_THING_CLOUDSTATE_MSG "/thing/ccu/cloudstate"
#define KK_THING_CLOUDSTATE_MSG "/thing/ccu/cloudstate
_reply
"
//const char DM_URI_SYS_PREFIX[] DM_READ_ONLY = "/sys/%s/%s/";
...
...
midware/midware/dm/kk_linkkit.c
View file @
6817d452
...
...
@@ -225,9 +225,15 @@ static void _iotx_linkkit_upstream_callback_remove(int msgid, int code)
extern
void
dm_server_free_context
(
_IN_
void
*
ctx
);
#endif
static
int
s_CloudStatus
=
0
;
static
int
s_CloudStatusRecv
=
0
;
int
kk_get_cloudstatus
(
void
){
return
s_CloudStatus
;
}
int
kk_get_cloud_recv_status
(
void
){
return
s_CloudStatusRecv
;
}
static
void
_iotx_linkkit_event_callback
(
iotx_dm_event_types_t
type
,
char
*
data
)
{
INFO_PRINT
(
"_iotx_linkkit_event_callback ================== [%s]
\n
"
,
data
);
...
...
@@ -295,6 +301,7 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
//kk_tsl_service_property_set(topic->valuestring, payload->valuestring, strlen(payload->valuestring), NULL);
}
else
if
(
strstr
(
typeJson
->
valuestring
,
KK_THING_CLOUDSTATE_MSG
)){
INFO_PRINT
(
"cloud state notify
\n
"
);
s_CloudStatusRecv
=
1
;
cJSON
*
paramStr
=
cJSON_GetObjectItem
(
payload
,
MSG_PARAMS_STR
);
cJSON
*
state
=
cJSON_GetObjectItem
(
paramStr
,
MSG_IOTClOUDSTATE_STR
);
s_CloudStatus
=
atoi
(
state
->
valuestring
);
...
...
midware/midware/midware.c
View file @
6817d452
...
...
@@ -566,6 +566,11 @@ void *ccu_property_monitor(void *args)
int
time_second
=
60
;
while
(
mid_ctx
->
g_ccuProChg_dispatch_thread_running
)
{
if
(
kk_get_cloud_recv_status
()
==
0
){
iotx_dm_ccu_cloud_check
();
sleep
(
10
);
continue
;
}
//dm_ota_yield(MID_YIELD_TIMEOUT_MS);
HAL_Get_IP
(
s_IP
,
NULL
);
res
=
kk_tsl_get_value
(
kk_tsl_get_property_value
,
0
,
KK_TSL_CCU_WANIP_IDENTIFIER
,
NULL
,
&
s_IP_TSL
);
...
...
zlog.conf
View file @
6817d452
...
...
@@ -30,7 +30,7 @@ normal = "%d %-6V (%f:%L) %m%n"
[
rules
]
*.
DEBUG
>
stdout
;
normal
*.
INFO
>
stdout
;
normal
*.*
"/home/kk/share/%c.log"
,
1
MB
*
2
;
normal
...
...
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