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
dd8992de
Commit
dd8992de
authored
Aug 24, 2020
by
chen.weican
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】增加主机上线上报功能
【提交人】陈伟灿
parent
e16ac3e1
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
234 additions
and
84 deletions
+234
-84
application/kcloud/kcloud_data_handle.c
application/kcloud/kcloud_data_handle.c
+7
-0
application/kcloud/kk_topic_mng.c
application/kcloud/kk_topic_mng.c
+2
-2
common/api/com_api.h
common/api/com_api.h
+0
-27
midware/midware/dm/kk_dm_api.c
midware/midware/dm/kk_dm_api.c
+16
-0
midware/midware/dm/kk_dm_mng.c
midware/midware/dm/kk_dm_mng.c
+85
-10
midware/midware/dm/kk_dm_msg.c
midware/midware/dm/kk_dm_msg.c
+46
-0
midware/midware/midware.c
midware/midware/midware.c
+64
-40
midware/midware/ota/iotx_ota.c
midware/midware/ota/iotx_ota.c
+14
-5
No files found.
application/kcloud/kcloud_data_handle.c
View file @
dd8992de
...
...
@@ -18,6 +18,9 @@
#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"
#define KK_FILTER_STATUS_ONLINE "/thing/status/online"
#define KK_FILTER_STATUS_ONLINE_REPLY "/thing/status/online_reply"
#define KK_CLOUDSTATE_MSG "/thing/ccu/cloudstate"
const
char
DM_MSG_TO_MIDDWARE
[]
=
"{
\"
msgtype
\"
:
\"
%s
\"
,
\"
productType
\"
:
\"
%s
\"
,
\"
productCode
\"
:
\"
%s
\"
,
\"
deviceCode
\"
:
\"
%s
\"
}"
;
...
...
@@ -94,6 +97,10 @@ static int _check_invalid_topic(const char* topic)
strstr
(
topic
,
KK_FILTER_LOGIN_TOPIC_REPLY
)
==
NULL
){
return
1
;
}
else
if
(
strstr
(
topic
,
KK_FILTER_STATUS_ONLINE
)
!=
NULL
&&
\
strstr
(
topic
,
KK_FILTER_STATUS_ONLINE_REPLY
)
==
NULL
){
return
1
;
}
return
0
;
}
...
...
application/kcloud/kk_topic_mng.c
View file @
dd8992de
...
...
@@ -103,7 +103,7 @@ int KK_Client_Gateway_Subscribe(void)
HAL_GetProduct_Code
(
productCode
);
HAL_Get_mac
(
deviceCode
);
return
_kk_client_subscribe
(
productCode
,
deviceCode
);
return
_kk_client_subscribe
(
productCode
,
"CCU_66666"
);
}
static
int
_kk_utils_topic
(
_IN_
const
char
*
name
,
_IN_
char
*
product_code
,
...
...
@@ -167,7 +167,7 @@ char* KK_Make_Topic(cJSON *info)
if
(
device_code
==
NULL
){
goto
errorreturn
;
}
if
(
strstr
(
type
->
valuestring
,
"/ota/device/inform"
)){
if
(
strstr
(
type
->
valuestring
,
"/ota/device/inform"
)
||
strstr
(
type
->
valuestring
,
"/ota/device/progress"
)
){
_kk_utils_topic_ota
(
type
->
valuestring
,
&
topic
);
}
else
{
...
...
common/api/com_api.h
View file @
dd8992de
...
...
@@ -28,33 +28,6 @@ typedef enum {
IPC_UNDEF
}
ipc_type
;
typedef
enum
{
/******MIDDWARE TO APP**************/
MSG_REGISTER
=
0
,
MSG_UNREGISTER
,
MSG_TOPOADD
,
MSG_TOPODELETE
,
MSG_TOPOGET
,
MSG_LISTFOUND
,
MSG_LOGIN
,
MSG_LOGOUT
,
MSG_PROPERTYPOST
,
MSG_EVENTPOST
,
MSG_SERVICERESPONSE
,
MSG_SETREPLY
,
MSG_OTA_PROCESS
,
MSG_OTA_INFORM
,
/*******APP TO MIDDWARE**************/
MSG_REGISTER_REPLY
,
MSG_TOPOADD_REPLY
,
MSG_OFFLINE_REPLY
,
MSG_LOGIN_REPLY
,
MSG_PROPERTYSET
,
MSG_OTA_UPGRADE
,
MSG_INVALID
,
}
kk_msg_type_t
;
#define MSG_TYPE_STR "msgtype"
#define MSG_PRODUCT_TYPE_STR "productType"
#define MSG_PRODUCT_CODE_STR "productCode"
...
...
midware/midware/dm/kk_dm_api.c
View file @
dd8992de
...
...
@@ -105,6 +105,22 @@ int iotx_dm_subdev_topo_del(_IN_ int devid)
return
res
;
}
int
iotx_dm_dev_online
(
_IN_
int
devid
)
{
int
res
=
0
;
if
(
devid
<
0
)
{
return
INVALID_PARAMETER
;
}
_dm_api_lock
();
res
=
dm_mgr_upstream_status_online
(
devid
);
_dm_api_unlock
();
return
res
;
}
int
iotx_dm_subdev_login
(
_IN_
int
devid
)
{
int
res
=
0
;
...
...
midware/midware/dm/kk_dm_mng.c
View file @
dd8992de
...
...
@@ -126,14 +126,6 @@ static int _dm_init_tsl_params(int devId)
ERROR_PRINT
(
"[%s][%d] res:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
res
);
}
/*******set port*************/
//port = HAL_Get_port();
//res = kk_tsl_set_value(kk_tsl_set_property_value,devId,KK_TSL_GATAWAY_PORT_IDENTIFIER,&port,NULL);
//if(res != SUCCESS_RETURN)
//{
//ERROR_PRINT("[%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
//}
/*******set wanState*************/
int
wanState
=
0
;
res
=
kk_tsl_set_value
(
kk_tsl_set_property_value
,
devId
,
KK_TSL_CCU_WANSTATE_IDENTIFIER
,
&
wanState
,
NULL
);
if
(
res
!=
SUCCESS_RETURN
)
...
...
@@ -299,6 +291,25 @@ int dm_mgr_search_mac_by_topic(_IN_ char* topic, _OU_ char mac[DEVI
return
SUCCESS_RETURN
;
}
int
dm_mgr_get_deviceType_by_mac
(
_IN_
char
deviceCode
[
DEVICE_MAC_MAXLEN
],
_OU_
int
*
deviceType
)
{
dm_mgr_ctx
*
ctx
=
_dm_mgr_get_ctx
();
dm_mgr_dev_node_t
*
node
=
NULL
;
list_for_each_entry
(
node
,
&
ctx
->
dev_list
,
linked_list
,
dm_mgr_dev_node_t
)
{
if
((
strlen
(
node
->
deviceCode
)
==
strlen
(
deviceCode
))
&&
(
memcmp
(
node
->
deviceCode
,
deviceCode
,
strlen
(
deviceCode
))
==
0
))
{
/* dm_log_debug("Device Found, Product Key: %s, Device Name: %s", product_key, device_name); */
if
(
node
)
{
*
deviceType
=
node
->
dev_type
;
}
return
SUCCESS_RETURN
;
}
}
ERROR_PRINT
(
"Device Not Found, deviceCode: %s
\n
"
,
deviceCode
);
return
FAIL_RETURN
;
}
int
dm_mgr_get_device_by_mac
(
_IN_
char
deviceCode
[
DEVICE_MAC_MAXLEN
],
_OU_
dm_mgr_dev_node_t
**
node
)
...
...
@@ -382,7 +393,7 @@ int dm_mgr_init(void)
//HAL_GetProduct_Code(device_name);
memset
(
deviceCode
,
0x0
,
sizeof
(
deviceCode
));
HAL_Get_mac
(
deviceCode
);
res
=
dm_mgr_device_create
(
KK_DM_DEVICE_CCU
,
KK_DM_CCU_DEVICE_PRODUCT_TYPE
,
KK_DM_CCU_DEVICE_PRODUCT_CODE
,
deviceCode
,
""
,
&
devId
);
res
=
dm_mgr_device_create
(
KK_DM_DEVICE_CCU
,
KK_DM_CCU_DEVICE_PRODUCT_TYPE
,
KK_DM_CCU_DEVICE_PRODUCT_CODE
,
"CCU_66666"
,
""
,
&
devId
);
if
(
res
!=
SUCCESS_RETURN
)
{
goto
ERROR
;
}
...
...
@@ -422,7 +433,7 @@ int dm_mgr_deinit(void)
return
SUCCESS_RETURN
;
}
const
char
DM_URI_THING_EVENT_POST
[]
=
"/thing/event/%
.*
s/post"
;
const
char
DM_URI_THING_EVENT_POST
[]
=
"/thing/event/%s/post"
;
const
char
DM_MSG_THING_UPSTREAM_REQUEST_PARAMS
[]
DM_READ_ONLY
=
"{
\"
value
\"
:%s,
\"
timestamp
\"
:
\"
%s
\"
}"
;
static
int
_dm_mgr_upstream_request_assemble
(
_IN_
int
msgid
,
_IN_
int
devid
,
...
...
@@ -927,6 +938,70 @@ int dm_mgr_upstream_thing_list_found(_IN_ int devid)
return
res
;
}
const
char
DM_URI_STATUS_ONLINE
[]
=
"/thing/status/online"
;
int
dm_mgr_upstream_status_online
(
_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
;
}
if
(
devid
!=
0
){
res
=
dm_mgr_get_device_by_mac
(
node
->
fatherMac
,
&
gw_node
);
if
(
res
!=
SUCCESS_RETURN
)
{
ERROR_PRINT
(
"ERROR [%s][%d] res:%d
\n
"
,
__FUNCTION__
,
__LINE__
,
res
);
return
FAIL_RETURN
;
}
memcpy
(
request
.
productType
,
gw_node
->
productType
,
strlen
(
gw_node
->
productType
));
memcpy
(
request
.
productCode
,
gw_node
->
productCode
,
strlen
(
gw_node
->
productCode
));
memcpy
(
request
.
deviceCode
,
gw_node
->
deviceCode
,
strlen
(
gw_node
->
deviceCode
));
}
else
{
memcpy
(
request
.
productType
,
node
->
productType
,
strlen
(
node
->
productType
));
memcpy
(
request
.
productCode
,
node
->
productCode
,
strlen
(
node
->
productCode
));
memcpy
(
request
.
deviceCode
,
node
->
deviceCode
,
strlen
(
node
->
deviceCode
));
}
request
.
msgTypeStr
=
DM_URI_STATUS_ONLINE
;
/* Get Params And Method */
res
=
dm_msg_status_online
(
node
->
productType
,
node
->
productCode
,
node
->
deviceCode
,
&
request
);
if
(
res
!=
SUCCESS_RETURN
)
{
return
FAIL_RETURN
;
}
/* 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_COMBINE_LOGIN
[]
=
"/thing/combine/login"
;
int
dm_mgr_upstream_combine_login
(
_IN_
int
devid
)
...
...
midware/midware/dm/kk_dm_msg.c
View file @
dd8992de
...
...
@@ -265,6 +265,52 @@ int dm_msg_thing_topo_delete(_IN_ char productType[PRODUCT_CODE_MAXLEN],
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
\"
}"
;
int
dm_msg_status_online
(
_IN_
char
productType
[
PRODUCT_TYPE_MAXLEN
],
_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
;
char
timestamp
[
DM_UTILS_UINT64_STRLEN
]
=
{
0
};
char
client_id
[
PRODUCT_TYPE_MAXLEN
+
DEVICE_CODE_MAXLEN
+
20
]
=
{
0
};
char
*
sign_method
=
DM_MSG_SIGN_METHOD_HMACSHA1
;
char
sign
[
64
]
=
{
0
};
if
(
request
==
NULL
||
productType
==
NULL
||
deviceCode
==
NULL
||
productCode
==
NULL
||
(
strlen
(
productType
)
>=
PRODUCT_TYPE_MAXLEN
)
||
(
strlen
(
deviceCode
)
>=
DEVICE_CODE_MAXLEN
)
||
(
strlen
(
productCode
)
>=
PRODUCT_CODE_MAXLEN
)
||
(
strlen
(
request
->
productType
)
>=
PRODUCT_TYPE_MAXLEN
)
||
(
strlen
(
request
->
deviceCode
)
>=
DEVICE_CODE_MAXLEN
))
{
return
INVALID_PARAMETER
;
}
/* TimeStamp */
HAL_Snprintf
(
timestamp
,
DM_UTILS_UINT64_STRLEN
,
"%llu"
,
(
unsigned
long
long
)
HAL_UptimeMs
());
/* dm_log_debug("Time Stamp: %s", timestamp); */
/* Params */
request
->
method
=
(
char
*
)
DM_MSG_COMBINE_STATUS_ONLINE_METHOD
;
params_len
=
strlen
(
DM_MSG_COMBINE_STATUS_ONLINE
)
+
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_COMBINE_STATUS_ONLINE
,
deviceCode
);
request
->
params
=
params
;
request
->
params_len
=
strlen
(
request
->
params
);
return
SUCCESS_RETURN
;
}
const
char
DM_MSG_COMBINE_LOGIN_SIGN_SOURCE
[]
DM_READ_ONLY
=
"clientId%sdeviceName%sproductKey%stimestamp%s"
;
...
...
midware/midware/midware.c
View file @
dd8992de
#include<stdio.h>
#include"com_api.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
...
...
@@ -16,10 +15,33 @@
#include "kk_tsl_common.h"
#include "kk_tsl_api.h"
#include "kk_dm_api.h"
#include "kk_dm_msg.h"
#include "kk_dm_mng.h"
#include "kk_log.h"
#include "kk_dm_queue.h"
char
*
g_filerToPlatTable
[]
=
{
{
KK_REGISTER_TOPIC_REPLY
},
{
KK_ADD_TOPIC_REPLY
},
{
KK_LOGIN_TOPIC_REPLY
},
{
KK_THING_OTA_DEVICE_UPGRADE
},
{
KK_THING_CLOUDSTATE_MSG
},
};
static
int
_kk_filter_to_plat
(
const
char
*
msgtype
)
{
int
i
=
0
,
num
=
0
;
num
=
sizeof
(
g_filerToPlatTable
);
for
(
i
=
0
;
i
<
num
;
i
++
){
if
(
strstr
(
msgtype
,
g_filerToPlatTable
[
i
]))
{
return
1
;
}
}
return
0
;
}
void
mid_cb
(
void
*
data
,
int
len
){
if
(
data
!=
NULL
){
...
...
@@ -27,7 +49,7 @@ void mid_cb(void* data, int len){
cJSON
*
json
;
cJSON
*
info_root
,
*
info
,
*
type
;
cJSON
*
payload
;
cJSON
*
product_type
,
*
device_nam
e
;
cJSON
*
deviceCod
e
;
int
res
;
void
*
buf
=
malloc
(
len
);
memcpy
(
buf
,
data
,
len
);
...
...
@@ -45,39 +67,31 @@ void mid_cb(void* data, int len){
{
info_root
=
cJSON_GetObjectItem
(
json
,
MSG_INFO_STR
);
info
=
cJSON_Parse
(
info_root
->
valuestring
);
product_type
=
cJSON_GetObjectItem
(
info
,
MSG_PRODUCT_TYPE_STR
);
device_name
=
cJSON_GetObjectItem
(
info
,
MSG_DEVICE_CODE_STR
);
deviceCode
=
cJSON_GetObjectItem
(
info
,
MSG_DEVICE_CODE_STR
);
type
=
cJSON_GetObjectItem
(
info
,
MSG_TYPE_STR
);
switch
(
atoi
(
type
->
valuestring
))
{
case
MSG_REGISTER_REPLY
:
case
MSG_TOPOADD_REPLY
:
case
MSG_LOGIN_REPLY
:
case
MSG_OTA_UPGRADE
:
case
MSG_OFFLINE_REPLY
:
printf
(
"This topic don't send to platform
\r\n
"
);
cJSON_Delete
(
info
);
return
;
default:
break
;
}
payload
=
cJSON_GetObjectItem
(
json
,
MSG_PAYLOAD_STR
);
char
mac
[
DEVICE_MAC_MAXLEN
]
=
{
0
};
res
=
dm_mgr_search_mac_by_pkdn
(
product_type
->
valuestring
,
device_name
->
valuestring
,
mac
);
if
(
res
!=
SUCCESS_RETURN
)
{
if
(
_kk_filter_to_plat
(
type
->
valuestring
)){
cJSON_Delete
(
json
);
cJSON_Delete
(
info
);
return
;
}
cJSON
*
jsonplay
=
cJSON_Parse
(
payload
->
valuestring
);
cJSON_AddStringToObject
(
jsonplay
,
"mac"
,
mac
);
void
*
out
=
cJSON_Print
(
jsonplay
);
printf
(
"dm_mgr_search_mac_by_topic out: %s
\r\n
"
,
out
);
kk_ipc_send_ex
(
IPC_MID2PLAT
,
out
,
strlen
(
out
),
"1122334455667788"
);
free
(
out
);
cJSON_Delete
(
jsonplay
);
return
;
}
int
DevType
=
dm_mgr_get_deviceType_by_mac
(
deviceCode
->
valuestring
);
if
(
DevType
==
KK_DM_DEVICE_GATEWAY
){
kk_ipc_send_ex
(
IPC_MID2PLAT
,
data
,
strlen
(
data
),
deviceCode
->
valuestring
);
//send to gw itself
}
else
if
(
DevType
==
KK_DM_DEVICE_SUBDEV
){
dm_mgr_dev_node_t
*
gw_node
=
NULL
;
res
=
dm_mgr_get_device_by_mac
(
deviceCode
->
valuestring
,
&
gw_node
);
if
(
res
!=
SUCCESS_RETURN
)
{
ERROR_PRINT
(
"res:%d
\n
"
,
res
);
cJSON_Delete
(
json
);
cJSON_Delete
(
info
);
return
;
}
kk_ipc_send_ex
(
IPC_MID2PLAT
,
data
,
strlen
(
data
),
gw_node
->
fatherMac
);
//send to sub device
}
else
{
ERROR_PRINT
(
"wrong type
\n
"
);
}
cJSON_Delete
(
json
);
cJSON_Delete
(
info
);
...
...
@@ -424,19 +438,19 @@ void *ccu_property_monitor(void *args)
//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
);
INFO_PRINT
(
"current ip:%s,db ip:%s
\n
"
,
s_IP
,
s_IP_TSL
);
if
(
res
!=
SUCCESS_RETURN
){
ERROR_PRINT
(
"kk_tsl_get_value Failed
\n
"
);
}
else
{
if
(
strcmp
(
s_IP
,
s_IP_TSL
)){
kk_tsl_set_value
(
kk_tsl_set_property_value
,
0
,
KK_TSL_CCU_WANIP_IDENTIFIER
,
NULL
,
s_IP
);
INFO_PRINT
(
"current ip:%s,db ip:%s
\n
"
,
s_IP
,
s_IP_TSL
);
needReport
=
1
;
}
}
res
=
kk_tsl_get_value
(
kk_tsl_get_property_value
,
0
,
KK_TSL_CCU_IOTCLOUD_IDENTIFIER
,
&
cloudState
,
NULL
);
INFO_PRINT
(
"current ip:%s,db ip:%s
\n
"
,
s_IP
,
s_IP_TSL
);
INFO_PRINT
(
"cloudState:%d,s_cloudStatus:%d
\n
"
,
cloudState
,
s_cloudStatus
);
if
(
res
!=
SUCCESS_RETURN
){
ERROR_PRINT
(
"kk_tsl_get_value Failed
\n
"
);
}
...
...
@@ -445,6 +459,7 @@ void *ccu_property_monitor(void *args)
}
else
{
s_cloudStatus
=
cloudState
;
INFO_PRINT
(
"cloudState:%d,s_cloudStatus:%d
\n
"
,
cloudState
,
s_cloudStatus
);
needReport
=
1
;
}
}
...
...
@@ -455,16 +470,26 @@ void *ccu_property_monitor(void *args)
time_second
=
10
;
}
if
(
needReport
&&
(
cloudState
==
1
)){
kk_tsl_post_property
(
0
,
NULL
);
//
kk_tsl_post_property(0,NULL);
needReport
=
0
;
if
(
alreadyRepord
==
0
){
iotx_dm_dev_online
(
0
);
//first online,report the online status
time_second
=
60
;
}
else
{
kk_tsl_post_property
(
0
,
NULL
);
}
alreadyRepord
=
1
;
}
INFO_PRINT
(
"time_second:%d,s_cloudStatus:%d
\n
"
,
time_second
,
s_cloudStatus
);
sleep
(
time_second
);
}
return
NULL
;
}
static
int
kk_set_product_info
(
void
)
{
HAL_SetProduct_Type
(
PRODUCT_TPYE
);
...
...
@@ -529,8 +554,7 @@ int main(const int argc, const char **argv)
if
(
res
<
0
)
{
ERROR_PRINT
(
"HAL_ThreadCreate Failed
\n
"
);
return
-
1
;
}
}
int
ct
=
0
;
for
(;;)
{
...
...
@@ -538,8 +562,8 @@ int main(const int argc, const char **argv)
kk_platMsg_dispatch
();
/*if (ct == 0){
ct =1;
void* buf = "{ \"msgId\": \"7\", \"version\": \"1.0\", \"mac\": \"588E81FFFED3834A\", \"method\": \"thing.topo.add\", \"params\": { \"AppVersion\": \"10\", \"deviceCode\": \"
588E81FFFED3834A
\", \"productType\": \"curtain\", \"productCode\": \"24\" }}";
kk_platMsg_handle(buf
, "1122334455667788"
);
void* buf = "{ \"msgId\": \"7\", \"version\": \"1.0\", \"mac\": \"588E81FFFED3834A\", \"method\": \"thing.topo.add\", \"params\": { \"AppVersion\": \"10\", \"deviceCode\": \"
1212121212121212
\", \"productType\": \"curtain\", \"productCode\": \"24\" }}";
kk_platMsg_handle(buf);
//kk_set_tsl_by_productKey("a1OYuSallan","model.json");
//kk_mid_subdev_add("a1OYuSallan","allanWno8yDdsjCX15iq","","aabbccddeeff1122");
}*/
...
...
midware/midware/ota/iotx_ota.c
View file @
dd8992de
...
...
@@ -511,7 +511,7 @@ do_exit:
#undef MSG_REQUEST_LEN
}
const
char
KK_URI_OTA_PROCESS
[]
=
"/ota/device/progress/%s/%s"
;
int
OTA_publishProgress
(
void
*
handle
,
char
*
payload
){
OTA_Struct_pt
h_ota
=
(
OTA_Struct_pt
)
handle
;
if
(
NULL
==
handle
)
{
...
...
@@ -523,28 +523,37 @@ int OTA_publishProgress(void *handle, char* payload){
OTA_LOG_ERROR
(
"payload is NULL
\n
"
);
return
IOT_OTAE_INVALID_PARAM
;
}
int
msgTypeLen
=
strlen
(
KK_URI_OTA_PROCESS
)
+
strlen
(
h_ota
->
product_key
)
+
strlen
(
h_ota
->
device_name
)
+
1
;
char
*
msgTypeStr
=
malloc
(
msgTypeLen
);
if
(
msgTypeStr
==
NULL
){
OTA_LOG_ERROR
(
"MALLOC is NULL
\n
"
);
return
IOT_OTAE_INVALID_PARAM
;
}
memset
(
msgTypeStr
,
0x0
,
msgTypeLen
);
HAL_Snprintf
(
msgTypeStr
,
msgTypeLen
,
KK_URI_OTA_PROCESS
,
h_ota
->
product_key
,
h_ota
->
device_name
);
/* inform OTA to topic: "/ota/device/progress/$(product_key)/$(device_name)" */
// int topicLen = strlen(DM_MSG_INFO) + strlen(h_ota->product_key) + strlen(h_ota->device_name) + 1;
int
topicLen
=
strlen
(
DM_MSG_INFO
)
+
10
+
strlen
(
h_ota
->
product_key
)
+
strlen
(
h_ota
->
device_name
)
+
1
;
int
topicLen
=
strlen
(
DM_MSG_INFO
)
+
10
+
msgTypeLen
+
strlen
(
h_ota
->
product_key
)
+
strlen
(
h_ota
->
device_name
)
+
1
;
char
*
topicBuf
=
malloc
(
topicLen
);
if
(
topicBuf
==
NULL
){
OTA_LOG_ERROR
(
"MALLOC is NULL
\n
"
);
free
(
msgTypeStr
);
return
IOT_OTAE_INVALID_PARAM
;
}
HAL_Snprintf
(
topicBuf
,
topicLen
,
DM_MSG_INFO
,
MSG_OTA_PROCESS
,
h_ota
->
product_key
,
h_ota
->
device_name
,
""
);
HAL_Snprintf
(
topicBuf
,
topicLen
,
DM_MSG_INFO
,
msgTypeStr
,
h_ota
->
product_key
,
h_ota
->
device_name
,
""
);
cJSON
*
root
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
root
,
"info"
,
topicBuf
);
cJSON_AddStringToObject
(
root
,
"payload"
,
payload
);
void
*
buf
=
cJSON_Print
(
root
);
kk_ipc_send
(
IPC_MID2APP
,
buf
,
strlen
(
buf
)
+
1
);
free
(
msgTypeStr
);
free
(
topicBuf
);
free
(
buf
);
cJSON_Delete
(
root
);
return
0
;
}
...
...
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